all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: devel: Highlight 'modify-phases' keywords.
@ 2015-09-25  8:05 Alex Kost
  2015-09-25 19:22 ` Ludovic Courtès
  0 siblings, 1 reply; 20+ messages in thread
From: Alex Kost @ 2015-09-25  8:05 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

Hello, I would like to add a usual keyword highlighting for some Guix
things (substitute-keyword-arguments, with-directory-excursion, etc.).

But this one is unusual, as along with 'modify-phases' itself, its
keywords ('add-after', 'delete', …) will also be highlighted.  IMO this
will make the code of the packages easier to read; or is it too
colorful?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-devel-Highlight-modify-phases-keywords.patch --]
[-- Type: text/x-diff, Size: 4121 bytes --]

From ed1c3871b81d4904d106a3ca5aadde2e1803d2a6 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Thu, 24 Sep 2015 20:10:29 +0300
Subject: [PATCH] emacs: devel: Highlight 'modify-phases' keywords.

* emacs/guix-guile.el (guix-guile-keyword-regexp): New function.
* emacs/guix-devel.el (guix-devel-faces): New custom group.
  (guix-devel-modify-phases-keyword): New face.
  (guix-devel-modify-phases-keyword-regexp,
  guix-devel-font-lock-keywords): New variables.
  (guix-devel-modify-phases-font-lock-matcher,
  guix-devel-modify-phases-font-lock-pre): New functions.
  (guix-devel-mode): Adjust to add/remove font-lock-keywords.
---
 emacs/guix-devel.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 emacs/guix-guile.el |  4 ++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/emacs/guix-devel.el b/emacs/guix-devel.el
index 6de49be..8a6fc1e 100644
--- a/emacs/guix-devel.el
+++ b/emacs/guix-devel.el
@@ -33,6 +33,16 @@
   "Settings for Guix development utils."
   :group 'guix)
 
+(defgroup guix-devel-faces nil
+  "Faces for `guix-devel-mode'."
+  :group 'guix-devel
+  :group 'guix-faces)
+
+(defface guix-devel-modify-phases-keyword
+  '((t :inherit font-lock-preprocessor-face))
+  "Face for a `modify-phases' keyword ('delete', 'replace', etc.)."
+  :group 'guix-devel-faces)
+
 (defcustom guix-devel-activate-mode t
   "If non-nil, then `guix-devel-mode' is automatically activated
 in Scheme buffers."
@@ -94,6 +104,41 @@ Interactively, use the module defined by the current scheme file."
                                       guix-use-substitutes)
                 "#:dry-run?" (guix-guile-boolean guix-dry-run)))))))
 
+\f
+;;; Font-lock
+
+(defvar guix-devel-modify-phases-keyword-regexp
+  (rx (+ word))
+  "Regexp for a 'modify-phases' keyword ('delete', 'replace', etc.).")
+
+(defun guix-devel-modify-phases-font-lock-matcher (limit)
+  "Find a 'modify-phases' keyword.
+This function is used as a MATCHER for `font-lock-keywords'."
+  (ignore-errors
+    (down-list)
+    (or (re-search-forward guix-devel-modify-phases-keyword-regexp
+                           limit t)
+        (set-match-data nil))
+    (up-list)
+    t))
+
+(defun guix-devel-modify-phases-font-lock-pre ()
+  "Skip the next sexp, and return the end point of the current list.
+This function is used as a PRE-MATCH-FORM for `font-lock-keywords'
+to find 'modify-phases' keywords."
+  (ignore-errors (forward-sexp))
+  (save-excursion (up-list) (point)))
+
+(defvar guix-devel-font-lock-keywords
+  `((,(guix-guile-keyword-regexp "modify-phases")
+     (1 'font-lock-keyword-face)
+     (guix-devel-modify-phases-font-lock-matcher
+      (guix-devel-modify-phases-font-lock-pre)
+      nil
+      (0 'guix-devel-modify-phases-keyword nil t))))
+  "A list of `font-lock-keywords' for `guix-devel-mode'.")
+
+\f
 (defvar guix-devel-keys-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "b") 'guix-devel-build-package-definition)
@@ -122,7 +167,15 @@ bindings:
 \\{guix-devel-mode-map}"
   :init-value nil
   :lighter " Guix"
-  :keymap guix-devel-mode-map)
+  :keymap guix-devel-mode-map
+  (if guix-devel-mode
+      (progn
+        (setq-local font-lock-multiline t)
+        (font-lock-add-keywords nil guix-devel-font-lock-keywords))
+    (setq-local font-lock-multiline nil)
+    (font-lock-remove-keywords nil guix-devel-font-lock-keywords))
+  (when font-lock-mode
+    (font-lock-fontify-buffer)))
 
 ;;;###autoload
 (defun guix-devel-activate-mode-maybe ()
diff --git a/emacs/guix-guile.el b/emacs/guix-guile.el
index 35a97d7..63322d7 100644
--- a/emacs/guix-guile.el
+++ b/emacs/guix-guile.el
@@ -59,6 +59,10 @@ Return nil, if current buffer does not define a module."
 Transform elisp ARG (nil or non-nil) to the guile boolean (#f or #t)."
   (concat "#" (prin1-to-string (if arg 't 'f))))
 
+(defun guix-guile-keyword-regexp (keyword)
+  "Return regexp to find guile KEYWORD."
+  (format "(\\(%s\\)\\_>" keyword))
+
 (defun guix-guile-make-call-expression (proc &rest args)
   "Return \"(PROC ARGS ...)\" string.
 PROC and ARGS should be strings."
-- 
2.5.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-10-15 17:42 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-25  8:05 [PATCH] emacs: devel: Highlight 'modify-phases' keywords Alex Kost
2015-09-25 19:22 ` Ludovic Courtès
2015-09-26 19:48   ` Alex Kost
2015-09-27 20:29     ` Ludovic Courtès
2015-09-28 12:26       ` .dir-locals.el vs. guix-devel-mode Alex Kost
2015-09-28 20:05         ` Taylan Ulrich Bayırlı/Kammer
2015-09-29 11:06           ` Alex Kost
2015-09-29 11:22             ` Taylan Ulrich Bayırlı/Kammer
2015-09-29 19:16         ` Ludovic Courtès
2015-10-01 21:10           ` Alex Kost
2015-10-01 21:34             ` Ludovic Courtès
2015-10-02 12:46               ` Alex Kost
2015-10-02 12:51                 ` Ludovic Courtès
2015-10-02 17:25                   ` Alex Kost
2015-10-12  9:33                   ` [PATCH] emacs: devel: Add indentation rules Alex Kost
2015-10-13  9:45                     ` Ludovic Courtès
2015-10-13 17:50                       ` Alex Kost
2015-10-14 20:00                         ` Ludovic Courtès
2015-10-15 17:42                           ` Alex Kost
2015-10-01 21:39             ` .dir-locals.el vs. guix-devel-mode Mathieu Lirzin

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.