* [Howm-eng 22] Re: Set buffer name of Howm file
@ 2006-02-24 16:30 khi
0 siblings, 0 replies; only message in thread
From: khi @ 2006-02-24 16:30 UTC (permalink / raw)
At Thu, 23 Feb 2006 09:29:06 -0500 (EST),
peter at exegenix.com wrote:
> 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.
Interesting idea :-)
Here is a modified my-howm-mode-set-buffer-name. It supports two or
more sections in one file.
# I personally like one file for one day.
# (setq howm-file-name-format "%Y/%m/%Y-%m-%d.howm")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar my-howm-buffer-name-limit 20)
(defvar my-howm-buffer-name-total-limit my-howm-buffer-name-limit)
(defun my-howm-truncate-string (string limit &optional dots-str)
"Truncate STRING if it is longer than LIMIT.
For example, \"1234567...\" is returned if string is \"123456789012\"
and limit is 10.
When DOTS is non-nil, it is used instead of \"...\"."
(let ((dots (or dots-str "...")))
(when (> (length dots) limit)
(setq dots (substring dots 0 limit)))
(if (> (length string) limit)
(concat (substring string 0 (- limit (length dots)))
dots)
string)))
(defun my-howm-mode-set-buffer-name ()
"Set the buffer name to the title at the top of the file."
(when (and howm-mode (buffer-file-name))
(save-excursion
(goto-char 0)
(let ((titles nil))
(while (re-search-forward howm-view-title-regexp nil t)
(setq titles
(cons (match-string-no-properties howm-view-title-regexp-pos)
titles)))
(let ((name (mapconcat
(lambda (s)
(my-howm-truncate-string s
my-howm-buffer-name-limit))
(reverse (howm-cl-remove-if (lambda (s) (string= s ""))
titles))
"/")))
(rename-buffer (my-howm-truncate-string name
my-howm-buffer-name-total-limit)
t))))))
(add-hook 'howm-mode-hook 'my-howm-mode-set-buffer-name)
(add-hook 'after-save-hook 'my-howm-mode-set-buffer-name)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
--
khi at users.sourceforge.jp
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-02-24 16:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-24 16:30 [Howm-eng 22] Re: Set buffer name of Howm file khi
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).