123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- (provide 'org-elisp-symbol)
- (require 'org)
- (org-add-link-type "elisp-symbol" 'org-elisp-symbol-open)
- (add-hook 'org-store-link-functions 'org-elisp-symbol-store-link)
- (defun org-elisp-symbol-open (path)
- "Visit the emacs-lisp elisp-symbol at PATH."
- (let* ((search (when (string-match "::\\(.+\\)\\'" path)
- (match-string 1 path)))
- (path (substring path 0 (match-beginning 0))))
- (org-open-file path t nil search)))
- (defun org-elisp-symbol-store-link ()
- "Store a link to an emacs-lisp elisp-symbol."
- (when (eq major-mode 'emacs-lisp-mode)
- (save-excursion
- (or (looking-at "^(") (beginning-of-defun))
- (looking-at "^(\\([a-z]+\\) \\([^)\n ]+\\) ?\n?[ \t]*\\(?:(\\(.*\\))\\)?")
- (let* ((end (save-excursion
- (save-match-data
- (end-of-defun) (point))))
- (def (match-string 1))
- (name (match-string 2))
- (sym-name (intern-soft name))
- (stype (cond ((commandp sym-name) "Command")
- ((functionp sym-name) "Function")
- ((user-variable-p sym-name) "User variable")
- ((string= def "defvar") "Variable")
- ((string= def "defmacro") "Macro")
- ((string= def "defun") "Function or command")
- (t "Symbol")))
- (args (if (match-string 3)
- (mapconcat (lambda (a) (unless (string-match "^&" a) a))
- (split-string (match-string 3)) " ")
- "no arg"))
- (docstring (cond ((functionp sym-name)
- (or (documentation sym-name)
- "[no documentation]"))
- ((string-match "[Vv]ariable" stype)
- (documentation-property sym-name
- 'variable-documentation))
- (t "no documentation")))
- (doc (and (string-match "^\\([^\n]+\\)$" docstring)
- (match-string 1 docstring)))
- (fixme (save-excursion
- (beginning-of-defun) (end-of-defun)
- (if (re-search-forward "^;+ ?FIXME[ :]*\\(.*\\)$" end t)
- (match-string 1) "nothing to fix")))
- (comment (save-excursion
- (beginning-of-defun) (end-of-defun)
- (if (re-search-forward "^;;+ ?\\(.*\\)$" end t)
- (match-string 1) "no comment")))
- keys keys-desc link description)
- (if (equal stype "Command")
- (setq keys (where-is-internal sym-name)
- keys-desc
- (if keys (mapconcat 'key-description keys " ") "none")))
- (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
- "::" def " " name))
- (setq description (concat stype ": " name))
- (org-store-link-props
- :type "elisp-symbol"
- :link link
- :description description
- :def def
- :name name
- :stype stype
- :args args
- :keys keys-desc
- :docstring docstring
- :doc doc
- :fixme fixme
- :comment comment)))))
- (provide 'org-elisp-symbol)
|