Peter Mielke
peter****@exege*****
Thu Feb 23 23:29:06 JST 2006
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)