all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: devel: Add indentation rules for 'modify-phases' keywords.
@ 2015-10-17 16:39 Alex Kost
  2015-10-19 15:44 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Kost @ 2015-10-17 16:39 UTC (permalink / raw
  To: guix-devel

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

Hello, currently Emacs indents our 'modify-phases' macro like this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-scheme, Size: 96 bytes --]

(modify-phases %standard-phases
  (add-before 'build 'foo-phase
              (lambda _ 'foo)))

[-- Attachment #3: Type: text/plain, Size: 11 bytes --]


or this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Type: text/x-scheme, Size: 88 bytes --]

(modify-phases %standard-phases
  (add-before
   'build 'foo-phase
   (lambda _ 'foo)))

[-- Attachment #5: Type: text/plain, Size: 57 bytes --]


While IMHO it is better to have it indented like this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: Type: text/x-scheme, Size: 86 bytes --]

(modify-phases %standard-phases
  (add-before 'build 'foo-phase
    (lambda _ 'foo)))

[-- Attachment #7: Type: text/plain, Size: 459 bytes --]


This patch will do it.  Of course we can just use:

(put 'replace 'scheme-indent-function 1)
(put 'add-after 'scheme-indent-function 2)
(put 'add-before 'scheme-indent-function 2)

But potentially these keywords may also be used outside 'modify-phases'.

So with the attached more complex rules, 'replace', 'add-before' and
'add-after' keywords will be indented specially only when they are
inside 'modify-phases', otherwise they will be indented as usual:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: Type: text/x-scheme, Size: 146 bytes --]

(modify-phases %standard-phases
  (replace 'build
    (lambda _ (zero? 0))))

(do-something
 (replace 'this
          'that
          'and-that))

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #9: 0001-emacs-devel-Add-indentation-rules-for-modify-phases-.patch --]
[-- Type: text/x-patch, Size: 1996 bytes --]

From 092dbb4460cf140c628eb4aeb4c5fff8f0083b3c Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Sat, 17 Oct 2015 19:02:39 +0300
Subject: [PATCH] emacs: devel: Add indentation rules for 'modify-phases'
 keywords.

* emacs/guix-devel.el: Add indentation rules for 'modify-phases' keywords.
  (guix-devel-indent-modify-phases-keyword,
  guix-devel-indent-modify-phases-keyword-1,
  guix-devel-indent-modify-phases-keyword-2): New functions.
---
 emacs/guix-devel.el | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/emacs/guix-devel.el b/emacs/guix-devel.el
index f3ad4b9..170ce1a 100644
--- a/emacs/guix-devel.el
+++ b/emacs/guix-devel.el
@@ -254,6 +254,20 @@ Each rule should have a form (SYMBOL VALUE).  See `put' for details."
                   0)))
     (lisp-indent-specform count state indent-point normal-indent)))
 
+(defun guix-devel-indent-modify-phases-keyword (count)
+  "Return indentation function for 'modify-phases' keywords."
+  (lambda (state indent-point normal-indent)
+    (when (ignore-errors
+            (goto-char (nth 1 state))   ; start of keyword sexp
+            (backward-up-list)
+            (looking-at "(modify-phases\\>"))
+      (lisp-indent-specform count state indent-point normal-indent))))
+
+(defalias 'guix-devel-indent-modify-phases-keyword-1
+  (guix-devel-indent-modify-phases-keyword 1))
+(defalias 'guix-devel-indent-modify-phases-keyword-2
+  (guix-devel-indent-modify-phases-keyword 2))
+
 (guix-devel-scheme-indent
   (bag 0)
   (build-system 0)
@@ -293,7 +307,12 @@ Each rule should have a form (SYMBOL VALUE).  See `put' for details."
   (with-monad 1)
   (with-mutex 1)
   (with-store 1)
-  (wrap-program 1))
+  (wrap-program 1)
+
+  ;; 'modify-phases' keywords:
+  (replace    'guix-devel-indent-modify-phases-keyword-1)
+  (add-after  'guix-devel-indent-modify-phases-keyword-2)
+  (add-before 'guix-devel-indent-modify-phases-keyword-2))
 
 \f
 (defvar guix-devel-keys-map
-- 
2.5.0


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

end of thread, other threads:[~2015-10-20 14:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-17 16:39 [PATCH] emacs: devel: Add indentation rules for 'modify-phases' keywords Alex Kost
2015-10-19 15:44 ` Ludovic Courtès
2015-10-20 14:07   ` Alex Kost

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.