Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add font-lock for el-patch-def* forms #38

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion el-patch.el
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ patched. NAME and TYPE are as returned by `el-patch-get'."
;;;###autoload
(progn
(cl-defmacro el-patch-deftype
(type &rest kwargs &key classify locate declare macro-name)
(type &rest kwargs &key classify locate declare macro-name font-lock)
"Allow `el-patch' to patch definitions of the given TYPE.
TYPE is a symbol like `defun', `define-minor-mode', etc. This
updates `el-patch-deftype-alist' (which see) with the provided
Expand All @@ -546,6 +546,8 @@ keyword arguments and defines a macro named like
;; code if somebody decides to mutate
;; `el-patch-deftype-alist'.
(copy-tree ',kwargs))
,(when font-lock
`(funcall ,font-lock ',type))
(defmacro ,(or macro-name (intern (format "el-patch-%S" type)))
(name &rest args)
,(format "Use `el-patch' to override a `%S' form.
Expand Down Expand Up @@ -584,6 +586,28 @@ similar."
(list (cons 'function function-name)
(cons 'variable variable-name))))

;;;;; Font-lock functions

(defun el-patch-fontify-as-defun (type)
"Fontify patch of TYPE as function definition."
(font-lock-add-keywords
'emacs-lisp-mode
`((,(concat
(format "(\\(el-patch-%S\\)\\>[[:blank:]]+\\(" type)
lisp-mode-symbol-regexp
"\\)[[:blank:]]")
(2 font-lock-function-name-face)))))

(defun el-patch-fontify-as-variable (type)
"Fontify patch of TYPE as variable definition."
(font-lock-add-keywords
'emacs-lisp-mode
`((,(concat
(format "(\\(el-patch-%S\\)\\>[[:blank:]]+\\(" type)
lisp-mode-symbol-regexp
"\\)[[:blank:]]")
(2 font-lock-variable-name-face)))))

;;;;; Location functions

(defmacro el-patch-wrap-locator (&rest body)
Expand Down Expand Up @@ -651,48 +675,55 @@ DEFINITION is a list starting with `defun' or similar."
(el-patch-deftype defconst
:classify el-patch-classify-variable
:locate el-patch-locate-variable
:font-lock #'el-patch-fontify-as-variable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, I'd like these to be unquoted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I personally prefer as little magic as possible especially with macros, so I pass quoted or unquoted based on how it is used later. But consistency almost always trumps purity :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think you are right about preferring quoted, and if I were designing this macro again then I would do it your way. It's not a good enough reason to break backwards compatibility, though :P

:declare ((doc-string 3)
(indent defun)))

;;;###autoload
(el-patch-deftype defcustom
:classify el-patch-classify-variable
:locate el-patch-locate-variable
:font-lock #'el-patch-fontify-as-variable
:declare ((doc-string 3)
(indent defun)))

;;;###autoload
(el-patch-deftype define-minor-mode
:classify el-patch-classify-define-minor-mode
:locate el-patch-locate-function
:font-lock #'el-patch-fontify-as-defun
:declare ((doc-string 2)
(indent defun)))

;;;###autoload
(el-patch-deftype defmacro
:classify el-patch-classify-function
:locate el-patch-locate-function
:font-lock #'el-patch-fontify-as-defun
:declare ((doc-string 3)
(indent defun)))

;;;###autoload
(el-patch-deftype defsubst
:classify el-patch-classify-function
:locate el-patch-locate-function
:font-lock #'el-patch-fontify-as-defun
:declare ((doc-string 3)
(indent defun)))

;;;###autoload
(el-patch-deftype defun
:classify el-patch-classify-function
:locate el-patch-locate-function
:font-lock #'el-patch-fontify-as-defun
:declare ((doc-string 3)
(indent defun)))

;;;###autoload
(el-patch-deftype defvar
:classify el-patch-classify-variable
:locate el-patch-locate-variable
:font-lock #'el-patch-fontify-as-variable
:declare ((doc-string 3)
(indent defun)))

Expand Down