[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Macro used for dynamic setting of font-lock-keywords
From: |
Sebastian Tennant |
Subject: |
Re: Macro used for dynamic setting of font-lock-keywords |
Date: |
Mon, 28 May 2007 12:22:44 +0300 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) |
Quoth Xavier Maillard <xma@gnu.org>:
> Hi,
>
> seem to get used as often as it probably should. I've seen people post 20+
> lines of elisp to this list to do something which could be achieved more
> reliably with 4 or five lines of defadvice.
>
> Advice is considered as *dangerous* and not to be used extensively.
>
Indeed this is what I've been lead to believe. I think RMS' position
on defadvice, which confirms this, is knocking about somewhere.
IMHO macros (at a user-level) are useful whenever you would otherwise
repeat yourself. For example, I like to keep technical notes in a
~/tech-notes directory and quotes in a ~/quotes directory. Rather
than write an interactive command for each I wrote a macro which I
called commandir:
(defmacro commandir (call pmt dir def)
`(defun ,call ()
(interactive)
(let (checked-dir filename)
;; checked-dir will always ends with a '/'
(setq checked-dir (file-name-as-directory ,dir))
;;accept user input
(setq filename (read-file-name ,pmt checked-dir))
(when (equal filename "") (setq filename ,def))
;;read file or create new buffer if file does not exist
;;(buffer is automatically selected for editing)
(find-file (concat checked-dir filename) nil)
.
.
.
I can now 'build' as many functions as I like, each providing quick
access to the contents of my various directories, with simple macro
calls like this one in my ~/.emacs file:
(commandir tn "Tech note: " "~/tech-notes" "misc")
Then it is a case of simply typing::
M-x tn <RET>
and I am prompted for a filename (with filename completion based on
the contents of ~/tech-notes"). If I enter the name of an exisitng
file, that file is visited, if I enter a non-existing file name, that
file will be created when the buffer is saved, and if I don't type
anything, ~/tech-notes/misc is visited.
Very handy indeed!
Sebastian