public inbox for howm-eng@lists.osdn.me
 help / color / mirror / Atom feed
* [Howm-eng 21] Set buffer name of Howm file
@ 2006-02-23 14:29 peter
  0 siblings, 0 replies; only message in thread
From: peter @ 2006-02-23 14:29 UTC (permalink / raw)


Hi,

I've just started using howm and enjoy it. Here is a snippet that i
wrote to set the buffer name to the title at the start of the
file. This to me is much more useful than knowing the filename.

Comments?



(defun my-howm-mode-set-buffer-name ()
  "Set the buffer name to the title at the top of the file."
  (save-excursion
    (goto-char 0)
    (if (and (buffer-file-name)
             (string-match "\\.howm" (buffer-name))
             (looking-at "=  *\\(.*\\)"))
        (let ((title (buffer-substring-no-properties (match-beginning 1)
                                                     (match-end 1))))

          (if (< 0 (length title))
              ;; check for a buffer with the same name
              (let* ((pat (concat "^" (regexp-quote title) "\\(<.*\\|\\)$"))
                     (count (eval (cons '+
                                        (mapcar '(lambda (x) (if (string-match pat x) 1 0))
                                                (mapcar 'buffer-name (delq (current-buffer) (buffer-list))))))))

                (if (= 0 count)
                    (rename-buffer title)
                  (rename-buffer (concat title "<" (int-to-string count) ">")))))))))

(add-hook 'howm-mode-hook 'my-howm-mode-set-buffer-name)



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-02-23 14:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-23 14:29 [Howm-eng 21] Set buffer name of Howm file peter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).