al-lisp.el 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;;; al-lisp.el --- Additional functionality for `lisp-mode'
  2. ;; Copyright © 2017 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'al-imenu)
  17. ;;; Highlighting "defcommand" (used by StumpWM)
  18. ;; To highlight docstring properly (with `font-lock-doc-face').
  19. (put 'defcommand 'doc-string-elt 4)
  20. (defvar al/lisp-defcommand-regexp
  21. (rx "(" (group "defcommand")
  22. symbol-end
  23. (zero-or-more blank)
  24. (zero-or-one "(")
  25. (zero-or-one
  26. (group (one-or-more (or (syntax word) (syntax symbol))))))
  27. "Regexp to match 'defcommand' keyword.")
  28. (defun al/lisp-add-defcommand-font-lock-keywords ()
  29. "Add font-lock keywords to highlight 'defcommand' properly.
  30. Call this function once!"
  31. (font-lock-add-keywords
  32. 'lisp-mode
  33. `((,al/lisp-defcommand-regexp
  34. (1 font-lock-keyword-face)
  35. (2 font-lock-function-name-face nil t)))))
  36. (defun al/lisp-add-defcommand-to-imenu ()
  37. "Add 'defcommand' entries to `imenu-generic-expression'.
  38. This function is intended to be added to `lisp-mode-hook'."
  39. (al/add-to-imenu al/lisp-defcommand-regexp
  40. :index 2))
  41. (provide 'al-lisp)
  42. ;;; al-lisp.el ends here