public inbox for howm-eng@lists.osdn.me
 help / color / mirror / Atom feed
From: khi at users.sourceforge.jp (khi at users.sourceforge.jp)
Subject: [Howm-eng 23] Re: Set buffer name of Howm file
Date: Sun, 12 Mar 2006 23:37:30 +0900	[thread overview]
Message-ID: <m31wx7zq39.wl@telperion.i> (raw)

Hi.

At Sat, 25 Feb 2006 01:30:13 +0900,
khi at users.sourceforge.jp wrote:
> Below is a modified my-howm-mode-set-buffer-name.  It supports two or
> more sections in one file.

That has a bug.  We need to exclude "no title" case.
Below is a fixed version.  thx > Anonymous (in Japanese)
http://howm.sourceforge.jp/cgi-bin/hiki/hiki.cgi?ExternalTool

In addition, I received a comment in the above page:
"This is so convenient. I expect it as a standard feature of howm."
Mielke-san, would you allow me to use your idea and code?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(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))
                     "/")))
          (when (not (string= name ""))  ;; exclude "no title" case
            (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


                 reply	other threads:[~2006-03-12 14:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m31wx7zq39.wl@telperion.i \
    --to=howm-eng@lists.osdn.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).