Menu

#1 Read package from -*- modeline

open
nobody
None
5
2001-11-19
2001-11-19
Raymond Toy
No

Sorry, the following isn't a patch. It's a new function
and a defadvice form to enable ilisp to get the package
from a -*- modeline instead looking for in-package
forms in the source. (I got tired of patching the
source, so I used a defadvice instead.)

Hope this is acceptable.

(defun parse-attribute-list (&optional buffer)
"Find the attribute list in the given buffer (or
current buffer, if
none) and return an alist of attribute/value pairs.
The attributes
are (lowercase) symbols, and the values are symbols or
lists."
(let ((buf (or buffer (current-buffer)))
attrib-alist end)
(save-excursion
(set-buffer buf)
(goto-char (point-min))
(end-of-line)
(setq end (point))
(goto-char (point-min))
(when (search-forward "-*-" end t)
(while (re-search-forward "\\s-*\\(\\sw+\\):\\s-*" end t)
;; Got a key word. Get it and then read the value.
(push (cons (intern (downcase
(buffer-substring (match-beginning 1)
(match-end 1))))
(list (read (current-buffer))))
attrib-alist)))
(nreverse attrib-alist))))

(defadvice lisp-buffer-package-internal (around
get-package-from-attribute activate)
"Try to find the package from the attribute line of
the file. If
not, use the standard technique to find the package."
(let* ((file-parsed-attributes (parse-attribute-list))
(pkg (and file-parsed-attributes (second (assoc
'package file-parsed-attributes)))))
;; If we found the package in the file attributes
massage it into
;; a valid package name. If not, look for
in-package or
;; def-package forms
(if pkg
(setq ad-return-value
(values (upcase (cond ((keywordp pkg)
(substring (symbol-name pkg) 1))
((symbolp pkg)
(symbol-name pkg))
((listp pkg)
(let ((p (first pkg)))
(if (symbolp p)
(symbol-name p)
p)))))
nil))
ad-do-it)
ad-return-value))

Discussion


Log in to post a comment.