el.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ;;; srecode/el.el --- Emacs Lisp specific arguments
  2. ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <eric@siege-engine.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Emacs Lisp specific handlers. To use these handlers in your
  18. ;; template, add the :name part to your template argument list.
  19. ;;
  20. ;; Error if not in a Emacs Lisp mode
  21. ;;; Code:
  22. (require 'srecode)
  23. (require 'srecode/semantic)
  24. (declare-function semanticdb-brute-find-tags-by-class "semantic/db-find")
  25. ;;;###autoload
  26. (defun srecode-semantic-handle-:el (dict)
  27. "Add macros into the dictionary DICT based on the current Emacs Lisp file.
  28. Adds the following:
  29. PRENAME - The common name prefix of this file."
  30. (let* ((names (append (semantic-find-tags-by-class 'function (current-buffer))
  31. (semantic-find-tags-by-class 'variable (current-buffer)))
  32. )
  33. (common (try-completion "" names)))
  34. (srecode-dictionary-set-value dict "PRENAME" common)
  35. ))
  36. ;;;###autoload
  37. (defun srecode-semantic-handle-:el-custom (dict)
  38. "Add macros into the dictionary DICT based on the current Emacs Lisp file.
  39. Adds the following:
  40. GROUP - The 'defgroup' name we guess you want for variables.
  41. FACEGROUP - The `defgroup' name you might want for faces."
  42. (require 'semantic/db-find)
  43. (let ((groups (semanticdb-strip-find-results
  44. (semanticdb-brute-find-tags-by-class 'customgroup)))
  45. (varg nil)
  46. (faceg nil)
  47. )
  48. ;; Pick the best group
  49. (while groups
  50. (cond ((string-match "face" (semantic-tag-name (car groups)))
  51. (setq faceg (car groups)))
  52. ((not varg)
  53. (setq varg (car groups)))
  54. (t
  55. ;; What about other groups?
  56. ))
  57. (setq groups (cdr groups)))
  58. ;; Double check the facegroup.
  59. (setq faceg (or faceg varg))
  60. ;; Setup some variables
  61. (srecode-dictionary-set-value dict "GROUP" (semantic-tag-name varg))
  62. (srecode-dictionary-set-value dict "FACEGROUP" (semantic-tag-name faceg))
  63. ))
  64. (define-mode-local-override srecode-semantic-apply-tag-to-dict
  65. emacs-lisp-mode (tagobj dict)
  66. "Apply Emacs Lisp specific features from TAGOBJ into DICT.
  67. Calls `srecode-semantic-apply-tag-to-dict-default' first."
  68. (srecode-semantic-apply-tag-to-dict-default tagobj dict)
  69. ;; Pull out the tag for the individual pieces.
  70. (let* ((tag (oref tagobj :prime))
  71. (doc (semantic-tag-docstring tag)))
  72. ;; It is much more common to have doc on ELisp.
  73. (srecode-dictionary-set-value dict "DOC" doc)
  74. (cond
  75. ;;
  76. ;; FUNCTION
  77. ;;
  78. ((eq (semantic-tag-class tag) 'function)
  79. (if (semantic-tag-get-attribute tag :user-visible-flag)
  80. (srecode-dictionary-set-value dict "INTERACTIVE" " (interactive)\n ")
  81. (srecode-dictionary-set-value dict "INTERACTIVE" ""))))))
  82. (provide 'srecode/el)
  83. ;; Local variables:
  84. ;; generated-autoload-file: "loaddefs.el"
  85. ;; generated-autoload-load-name: "srecode/el"
  86. ;; End:
  87. ;;; srecode/el.el ends here