[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
refactor emacs lisp code, macros, byte-compiling, fun fun fun
From: |
Le Wang |
Subject: |
refactor emacs lisp code, macros, byte-compiling, fun fun fun |
Date: |
Wed, 21 Sep 2011 13:06:55 +0800 |
I have this in an init file which gets compiled:
(defadvice find-function-search-for-symbol (after oxy-adv1 last (symbol type library) activate)
"mark system files `read-only'"
(with-current-buffer (car ad-return-value)
(when (or (backup-file-name-p buffer-file-name)
(not (string-match (concat "\\`" (regexp-quote (expand-file-name "~")))
buffer-file-name)))
;; (view-mode 1)
(setq buffer-read-only t))))
(defadvice find-variable-noselect (after oxy-adv2 last (variable &optional file) activate)
"mark system files `read-only'"
(with-current-buffer (car ad-return-value)
(when (or (backup-file-name-p buffer-file-name)
(not (string-match (concat "\\`" (regexp-quote (expand-file-name "~")))
buffer-file-name)))
(setq buffer-read-only t))))
I want to factor out the common logic in the defadvice, *without* polluting the global name-space.
I got to:
(labels ((doit ()
(with-current-buffer (car ad-return-value)
(when (or (backup-file-name-p buffer-file-name)
(not (string-match (concat "\\`" (regexp-quote (expand-file-name "~")))
buffer-file-name)))
;; (view-mode 1)
(setq buffer-read-only t)))))
(defadvice find-function-search-for-symbol (after oxy-adv1 last (symbol type library) activate)
"mark system files `read-only'"
(doit))
(defadvice find-variable-noselect (after oxy-adv2 last (variable &optional file) activate)
"mark system files `read-only'"
(do-it)))
Which is great. I'm really liking this lisp thing now. But is there a way to make `do-it' not appear in the byte-code at all, but its expansion does. Like a macro
I've tried:
(macrolet ((doit ()
`(with-current-buffer (car ad-return-value)
(when (or (backup-file-name-p buffer-file-name)
(not (string-match (concat "\\`" (regexp-quote (expand-file-name "~")))
buffer-file-name)))
(setq buffer-read-only t)))))
(defadvice find-function-search-for-symbol (after oxy-adv1 last (symbol type library) activate)
"mark system files `read-only'"
(doit))
(defadvice find-variable-noselect (after oxy-adv2 last (variable &optional file) activate)
"mark system files `read-only'"
(do-it)))
But macrolet does dynamic binding, so it's not what I want. And (do-it) still appears in the byte-code. Is there something that does what I want?
--
Le
- refactor emacs lisp code, macros, byte-compiling, fun fun fun,
Le Wang <=