[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
defmacro is worse than my neighbours cat
From: |
Lennart Borgman (gmail) |
Subject: |
defmacro is worse than my neighbours cat |
Date: |
Fri, 12 Sep 2008 23:13:10 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 |
defmacro is worse than my neighbour's cat. When I think I everything is
fine and I calm down they bite.
I have a defmacro where I define a function and I want to build the doc
string for this function in a certain way. This works fine - until I
byte compile it. Can someone please try to explain to me how I can do
what I want?
Below is the defmacro. Look for "fix-me".
(defmacro define-mumamo-multi-major-mode (fun-sym spec-doc chunks)
"Define a function that turn on support for multiple major modes."
(let* ((mumamo-describe-chunks (make-symbol "mumamo-describe-chunks"))
(turn-on-fun (if (symbolp fun-sym)
(symbol-value
(intern
(symbol-name (quote fun-sym))))
(error "Parameter FUN-SYM must be a symbol")))
(turn-on-fun-alias (intern
(concat "mumamo-alias-"
(symbol-name
(symbol-value
(intern
(symbol-name (quote fun-sym))))))))
(turn-on-hook (intern (concat (symbol-name turn-on-fun) "-hook")))
(turn-on-map (intern (concat (symbol-name turn-on-fun) "-map")))
(turn-on-hook-doc (concat "Hook run at the very end of `"
(symbol-name turn-on-fun) "'."))
(chunks2 (if (symbolp chunks)
(symbol-value chunks)
chunks))
(docstring
(concat
spec-doc
"
This function is called a multi major mode. The main use for it
is in `auto-mode-alist' to have Emacs do this setup whenever you
open a file named in a certain way. \(You can of course call
this function directly yourself too.)
It sets up for multiple mode in the following way:
"
;; Fix-me: During byte compilation the next line is not
;; expanded as I thought because the functions in CHUNK is
;; not defined. How do I fix this?
(funcall 'mumamo-describe-chunks chunks2)
"
At the very end this multi major mode function runs first the hook
`mumamo-turn-on-hook' and then `" (symbol-name turn-on-hook) "'.
There is a keymap specific to this multi major mode, but it is
not returned by `current-local-map' which returns the chunk's
major mode's local keymap.
The keymap is named `" (symbol-name turn-on-map) "'.
This major mode has an alias `mumamo-alias-"
(symbol-name turn-on-fun) "'.
For more information see `define-mumamo-multi-major-mode'."
)))
`(progn
(add-to-list 'mumamo-defined-turn-on-functions (cons (car
',chunks2) ',turn-on-fun))
(defvar ,turn-on-hook nil ,turn-on-hook-doc)
(defvar ,turn-on-map (make-sparse-keymap)
,(concat "Keymap for multi major mode function `"
(symbol-name turn-on-fun) "'"))
(defvar ,turn-on-fun nil)
(make-variable-buffer-local ',turn-on-fun)
(put ',turn-on-fun 'permanent-local t)
(defun ,turn-on-fun nil ,docstring
(interactive)
(let ((old-major-mode (or mumamo-major-mode
major-mode)))
(kill-all-local-variables)
(run-hooks 'change-major-mode-hook)
(setq mumamo-multi-major-mode ',turn-on-fun)
(setq ,turn-on-fun t)
(mumamo-add-multi-keymap ',turn-on-fun ,turn-on-map)
(setq mumamo-current-chunk-family (copy-tree ',chunks2))
(mumamo-turn-on-actions old-major-mode)
(run-hooks ',turn-on-hook)))
(defalias ',turn-on-fun-alias ',turn-on-fun)
)))
- defmacro is worse than my neighbours cat,
Lennart Borgman (gmail) <=