unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH 2/3] emacs: Add key bindings for 'guix-build-log-minor-mode'.
@ 2015-10-29 20:33 Alex Kost
  2015-10-30 16:51 ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Kost @ 2015-10-29 20:33 UTC (permalink / raw)
  To: guix-devel

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

I use (add-hook 'shell-mode-hook 'guix-build-log-minor-mode) and I found
that along with phases highlighting, it is useful to have some key
bindings available in this minor mode, so this patch adds "C-c
M-n/M-p/TAB/S-TAB" keys to it.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-emacs-Add-key-bindings-for-guix-build-log-minor-mode.patch --]
[-- Type: text/x-patch, Size: 4178 bytes --]

From fe50e7233fa5144f31f7db583d0289f056dd9dd0 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Thu, 29 Oct 2015 21:27:56 +0300
Subject: [PATCH 2/3] emacs: Add key bindings for 'guix-build-log-minor-mode'.

* emacs/guix-build-log.el (guix-build-log-mode-map): Move keys to ...
  (guix-build-log-common-map): ...here.  New variable.
  (guix-build-log-minor-mode-map): New variable.
  (guix-build-log-minor-mode): Use it.
* doc/emacs.texi (Emacs Build Log): Document it.
---
 doc/emacs.texi          | 13 +++++++------
 emacs/guix-build-log.el | 24 +++++++++++++++++++++---
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/doc/emacs.texi b/doc/emacs.texi
index b36e859..03dc951 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -646,12 +646,13 @@ Toggle (show/hide) the bodies of all build phases.
 @end table
 
 There is also @kbd{M-x guix-build-log-minor-mode} which also provides
-the same highlighting (but not key bindings).  And as it is a minor
-mode, it can be enabled in any buffer.  For example, if you are building
-some package in a shell buffer (@pxref{Interactive Shell,,, emacs, The
-GNU Emacs Manual}), you may enable @command{guix-build-log-minor-mode}
-to make it more colorful.  Guix build output is rather specific, so this
-new highlighting shouldn't conflict with the existing one.
+the same highlighting.  And as it is a minor mode, it can be enabled in
+any buffer.  For example, if you are building some package in a shell
+buffer (@pxref{Interactive Shell,,, emacs, The GNU Emacs Manual}), you
+may enable @command{guix-build-log-minor-mode} to make it more colorful.
+Guix build output is rather specific, so this new highlighting shouldn't
+conflict with the existing one.  This mode also provides the same key
+bindings as the major mode, but prefixed with @kbd{C-c}.
 
 
 @node Emacs Completions
diff --git a/emacs/guix-build-log.el b/emacs/guix-build-log.el
index 0e13213..1242607 100644
--- a/emacs/guix-build-log.el
+++ b/emacs/guix-build-log.el
@@ -178,9 +178,8 @@ STATE is a symbol denoting how a build phase was ended.  It should be
      (3 'guix-build-log-phase-seconds prepend)))
   "A list of `font-lock-keywords' for `guix-build-log-mode'.")
 
-(defvar guix-build-log-mode-map
+(defvar guix-build-log-common-map
   (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map special-mode-map)
     (define-key map (kbd "M-n") 'guix-build-log-next-phase)
     (define-key map (kbd "M-p") 'guix-build-log-previous-phase)
     (define-key map (kbd "TAB") 'guix-build-log-phase-toggle)
@@ -188,8 +187,24 @@ STATE is a symbol denoting how a build phase was ended.  It should be
     (define-key map (kbd "<backtab>") 'guix-build-log-phase-toggle-all)
     (define-key map [(shift tab)] 'guix-build-log-phase-toggle-all)
     map)
+  "Parent keymap for 'build-log' buffers.
+For `guix-build-log-mode' this map is used as is.
+For `guix-build-log-minor-mode' this map is prefixed with 'C-c'.")
+
+(defvar guix-build-log-mode-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent
+     map (make-composed-keymap (list guix-build-log-common-map)
+                               special-mode-map))
+    map)
   "Keymap for `guix-build-log-mode' buffers.")
 
+(defvar guix-build-log-minor-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-c") guix-build-log-common-map)
+    map)
+  "Keymap for `guix-build-log-minor-mode' buffers.")
+
 (defun guix-build-log-phase-start (&optional with-header?)
   "Return the start point of the current build phase.
 If WITH-HEADER? is non-nil, do not skip 'starting phase ...' header.
@@ -319,9 +334,12 @@ When Guix Build Log minor mode is enabled, it highlights build
 log in the current buffer.  This mode can be enabled
 programmatically using hooks:
 
-  (add-hook 'shell-mode-hook 'guix-build-log-minor-mode)"
+  (add-hook 'shell-mode-hook 'guix-build-log-minor-mode)
+
+\\{guix-build-log-minor-mode-map}"
   :init-value nil
   :lighter " Guix-Build-Log"
+  :keymap guix-build-log-minor-mode-map
   :group 'guix-build-log
   (if guix-build-log-minor-mode
       (font-lock-add-keywords nil guix-build-log-font-lock-keywords)
-- 
2.5.0


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

* Re: [PATCH 2/3] emacs: Add key bindings for 'guix-build-log-minor-mode'.
  2015-10-29 20:33 [PATCH 2/3] emacs: Add key bindings for 'guix-build-log-minor-mode' Alex Kost
@ 2015-10-30 16:51 ` Ludovic Courtès
  2015-10-31 20:42   ` [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers Alex Kost
  0 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2015-10-30 16:51 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> I use (add-hook 'shell-mode-hook 'guix-build-log-minor-mode) and I found
> that along with phases highlighting, it is useful to have some key
> bindings available in this minor mode, so this patch adds "C-c
> M-n/M-p/TAB/S-TAB" keys to it.

Excellent!

> From fe50e7233fa5144f31f7db583d0289f056dd9dd0 Mon Sep 17 00:00:00 2001
> From: Alex Kost <alezost@gmail.com>
> Date: Thu, 29 Oct 2015 21:27:56 +0300
> Subject: [PATCH 2/3] emacs: Add key bindings for 'guix-build-log-minor-mode'.
>
> * emacs/guix-build-log.el (guix-build-log-mode-map): Move keys to ...
>   (guix-build-log-common-map): ...here.  New variable.
>   (guix-build-log-minor-mode-map): New variable.
>   (guix-build-log-minor-mode): Use it.
> * doc/emacs.texi (Emacs Build Log): Document it.

OK to push.

> +  (add-hook 'shell-mode-hook 'guix-build-log-minor-mode)

I wonder if we should do that automatically by default.  That way
everyone would get the cool features, even those who didn’t bother to
read all the manual.

WDYT?

Thanks,
Ludo’.

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

* [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers.
  2015-10-30 16:51 ` Ludovic Courtès
@ 2015-10-31 20:42   ` Alex Kost
  2015-11-01 17:46     ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Kost @ 2015-10-31 20:42 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Ludovic Courtès (2015-10-30 19:51 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
[...]
>> +  (add-hook 'shell-mode-hook 'guix-build-log-minor-mode)
>
> I wonder if we should do that automatically by default.  That way
> everyone would get the cool features, even those who didn’t bother to
> read all the manual.
>
> WDYT?

Not sure if it's really worth, but this can be done the same way as with
enabling 'guix-devel-mode' (as in the attached patch).  So it can be
disabled by:

  (setq guix-build-log-minor-mode-activate nil)

But then why don't we enable 'guix-prettify-mode' by default?  As for
me, I don't think all these features should be automatically enabled,
dunno what is considered to be a good default: "full-featured" or "as
simple as possible".


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-Enable-guix-build-log-minor-mode-in-shell-buff.patch --]
[-- Type: text/x-patch, Size: 3163 bytes --]

From 3991193fcc6700b1e198d5befcb6b1c651839ae0 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Sat, 31 Oct 2015 22:01:45 +0300
Subject: [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers.

* emacs/guix-build-log.el (guix-build-log-minor-mode-activate): New variable.
  (guix-build-log-minor-mode-activate-maybe): New function.
* emacs/guix-init.el: Add it to 'shell-mode-hook'.
* doc/emacs.texi (Emacs Build Log): Mention it.
---
 doc/emacs.texi          | 12 +++++-------
 emacs/guix-build-log.el | 13 +++++++++++++
 emacs/guix-init.el      |  1 +
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/doc/emacs.texi b/doc/emacs.texi
index 03dc951..e4608f0 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -646,13 +646,11 @@ Toggle (show/hide) the bodies of all build phases.
 @end table
 
 There is also @kbd{M-x guix-build-log-minor-mode} which also provides
-the same highlighting.  And as it is a minor mode, it can be enabled in
-any buffer.  For example, if you are building some package in a shell
-buffer (@pxref{Interactive Shell,,, emacs, The GNU Emacs Manual}), you
-may enable @command{guix-build-log-minor-mode} to make it more colorful.
-Guix build output is rather specific, so this new highlighting shouldn't
-conflict with the existing one.  This mode also provides the same key
-bindings as the major mode, but prefixed with @kbd{C-c}.
+the same highlighting and the same key bindings as the major mode, but
+prefixed with @kbd{C-c}.  By default, this minor mode is enabled in
+shell buffers (@pxref{Interactive Shell,,, emacs, The GNU Emacs
+Manual}).  If you don't like it, set
+@code{guix-build-log-minor-mode-activate} to nil.
 
 
 @node Emacs Completions
diff --git a/emacs/guix-build-log.el b/emacs/guix-build-log.el
index ae2631e..9e34525 100644
--- a/emacs/guix-build-log.el
+++ b/emacs/guix-build-log.el
@@ -104,6 +104,12 @@
   "Face for the number of seconds for a phase."
   :group 'guix-build-log-faces)
 
+(defcustom guix-build-log-minor-mode-activate t
+  "If non-nil, then `guix-build-log-minor-mode' is automatically
+activated in `shell-mode' buffers."
+  :type 'boolean
+  :group 'guix-build-log)
+
 (defcustom guix-build-log-mode-hook '()
   "Hook run after `guix-build-log-mode' is entered."
   :type 'hook
@@ -324,6 +330,13 @@ forward."
   (setq font-lock-defaults '(guix-build-log-font-lock-keywords t)))
 
 ;;;###autoload
+(defun guix-build-log-minor-mode-activate-maybe ()
+  "Activate `guix-build-log-minor-mode' depending on
+`guix-build-log-minor-mode-activate' variable."
+  (when guix-build-log-minor-mode-activate
+    (guix-build-log-minor-mode)))
+
+;;;###autoload
 (define-minor-mode guix-build-log-minor-mode
   "Toggle Guix Build Log minor mode.
 
diff --git a/emacs/guix-init.el b/emacs/guix-init.el
index 4b3d9c2..1612dee 100644
--- a/emacs/guix-init.el
+++ b/emacs/guix-init.el
@@ -15,5 +15,6 @@ avoid loading autoloads of Emacs packages installed in
   (guix-emacs-load-autoloads 'all))
 
 (add-hook 'scheme-mode-hook 'guix-devel-activate-mode-maybe)
+(add-hook 'shell-mode-hook 'guix-build-log-minor-mode-activate-maybe)
 
 (provide 'guix-init)
-- 
2.5.0


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

* Re: [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers.
  2015-10-31 20:42   ` [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers Alex Kost
@ 2015-11-01 17:46     ` Ludovic Courtès
  2015-11-02 13:01       ` Alex Kost
  0 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2015-11-01 17:46 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Not sure if it's really worth, but this can be done the same way as with
> enabling 'guix-devel-mode' (as in the attached patch).  So it can be
> disabled by:
>
>   (setq guix-build-log-minor-mode-activate nil)

OK.

> But then why don't we enable 'guix-prettify-mode' by default?  As for
> me, I don't think all these features should be automatically enabled,
> dunno what is considered to be a good default: "full-featured" or "as
> simple as possible".

I’m mostly in favor of full-featured.  The Emacs tradition is/was to
provide something that had to be explicitly configured to get the
features: in the old days, font-locking was disabled by default, and
Gnus would do absolutely nothing until you had spent a couple of days
configuring it.

However, given the wealth of features now provided by guix.el, I think
it’s best to enable most of them by default, at least those that are not
controversial.  Otherwise, the risk is that people just won’t know about
them.

‘guix-build-log-minor-mode’ is clearly one of the things to enable by
default IMO.  The situation is less clear for ‘guix-prettify-mode’
because it changes the behavior of Emacs in a way that could be
surprising to a newcomer.

WDYT?

> From 3991193fcc6700b1e198d5befcb6b1c651839ae0 Mon Sep 17 00:00:00 2001
> From: Alex Kost <alezost@gmail.com>
> Date: Sat, 31 Oct 2015 22:01:45 +0300
> Subject: [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers.
>
> * emacs/guix-build-log.el (guix-build-log-minor-mode-activate): New variable.
>   (guix-build-log-minor-mode-activate-maybe): New function.
> * emacs/guix-init.el: Add it to 'shell-mode-hook'.
> * doc/emacs.texi (Emacs Build Log): Mention it.

OK!

Ludo’.

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

* Re: [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers.
  2015-11-01 17:46     ` Ludovic Courtès
@ 2015-11-02 13:01       ` Alex Kost
  2015-11-02 14:14         ` Ludovic Courtès
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Kost @ 2015-11-02 13:01 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

Ludovic Courtès (2015-11-01 20:46 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
[...]
>> But then why don't we enable 'guix-prettify-mode' by default?  As for
>> me, I don't think all these features should be automatically enabled,
>> dunno what is considered to be a good default: "full-featured" or "as
>> simple as possible".
>
> I’m mostly in favor of full-featured.  The Emacs tradition is/was to
> provide something that had to be explicitly configured to get the
> features: in the old days, font-locking was disabled by default, and
> Gnus would do absolutely nothing until you had spent a couple of days
> configuring it.
>
> However, given the wealth of features now provided by guix.el, I think
> it’s best to enable most of them by default, at least those that are not
> controversial.  Otherwise, the risk is that people just won’t know about
> them.
>
> ‘guix-build-log-minor-mode’ is clearly one of the things to enable by
> default IMO.  The situation is less clear for ‘guix-prettify-mode’
> because it changes the behavior of Emacs in a way that could be
> surprising to a newcomer.
>
> WDYT?

OK, you convinced me.  I would not be happy if Emacs was not colored
(with disabled font-locking) when I first met it.  Thank you for the
descriptive explanation!  Now I agree on enabling
'guix-build-log-minor-mode' (and not enabling 'guix-prettify-mode').

-- 
Alex

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

* Re: [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers.
  2015-11-02 13:01       ` Alex Kost
@ 2015-11-02 14:14         ` Ludovic Courtès
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Courtès @ 2015-11-02 14:14 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Ludovic Courtès (2015-11-01 20:46 +0300) wrote:
>
>> Alex Kost <alezost@gmail.com> skribis:
>>
> [...]
>>> But then why don't we enable 'guix-prettify-mode' by default?  As for
>>> me, I don't think all these features should be automatically enabled,
>>> dunno what is considered to be a good default: "full-featured" or "as
>>> simple as possible".
>>
>> I’m mostly in favor of full-featured.  The Emacs tradition is/was to
>> provide something that had to be explicitly configured to get the
>> features: in the old days, font-locking was disabled by default, and
>> Gnus would do absolutely nothing until you had spent a couple of days
>> configuring it.
>>
>> However, given the wealth of features now provided by guix.el, I think
>> it’s best to enable most of them by default, at least those that are not
>> controversial.  Otherwise, the risk is that people just won’t know about
>> them.
>>
>> ‘guix-build-log-minor-mode’ is clearly one of the things to enable by
>> default IMO.  The situation is less clear for ‘guix-prettify-mode’
>> because it changes the behavior of Emacs in a way that could be
>> surprising to a newcomer.
>>
>> WDYT?
>
> OK, you convinced me.  I would not be happy if Emacs was not colored
> (with disabled font-locking) when I first met it.  Thank you for the
> descriptive explanation!  Now I agree on enabling
> 'guix-build-log-minor-mode' (and not enabling 'guix-prettify-mode').

Great!  :-)

Ludo’.

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

end of thread, other threads:[~2015-11-02 14:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-29 20:33 [PATCH 2/3] emacs: Add key bindings for 'guix-build-log-minor-mode' Alex Kost
2015-10-30 16:51 ` Ludovic Courtès
2015-10-31 20:42   ` [PATCH] emacs: Enable 'guix-build-log-minor-mode' in shell buffers Alex Kost
2015-11-01 17:46     ` Ludovic Courtès
2015-11-02 13:01       ` Alex Kost
2015-11-02 14:14         ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).