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 #49

Closed
wants to merge 1 commit 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 @@ -531,7 +531,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 @@ -547,6 +547,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
`(,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 @@ -585,6 +587,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)
Copy link
Contributor

@haji-ali haji-ali Mar 1, 2021

Choose a reason for hiding this comment

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

Shouldn't this account for macroname in case it is not nil in el-patch-deftype?

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, that's right. I... am not sure why I implemented this macro-name feature in the first place, but yes, it should be supported here as long as we've got it.

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 @@ -664,48 +688,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
: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