From mboxrd@z Thu Jan 1 00:00:00 1970 From: peter at exegenix.com (Peter Mielke) Date: Thu, 23 Feb 2006 09:29:06 -0500 (EST) Subject: [Howm-eng 21] Set buffer name of Howm file Message-ID: <20060223142906.2CCE25A704@yen.exegenix.com> 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)