unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Add 'pretty-sha-path'.
@ 2014-11-04 16:48 Alex Kost
  2014-11-04 19:39 ` Mark H Weaver
  2014-11-04 21:37 ` Ludovic Courtès
  0 siblings, 2 replies; 10+ messages in thread
From: Alex Kost @ 2014-11-04 16:48 UTC (permalink / raw)
  To: guix-devel

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

Hello,

Ludovic suggested to include “pretty-sha-path.el” in the repo, so here
is the patch for that.

Also I forgot to mention “emacs/guix-messages.el” in “emacs.am” in
commit 62f261d, so I did it in this patch (I hope it's not too evil :-))


[-- Attachment #2: 0001-emacs-Add-pretty-sha-path.patch --]
[-- Type: text/x-diff, Size: 10522 bytes --]

From e7ca6550d7f33d894e0023e3305938fce365fdba Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Tue, 4 Nov 2014 19:38:27 +0300
Subject: [PATCH] emacs: Add 'pretty-sha-path'.

* emacs/pretty-sha-path.el: New file.
* emacs.am (ELFILES): Add it.
* doc/emacs.texi (Emacs Pretty Path): New node.
---
 doc/emacs.texi           |  41 ++++++++++
 emacs.am                 |   4 +-
 emacs/pretty-sha-path.el | 200 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 244 insertions(+), 1 deletion(-)
 create mode 100644 emacs/pretty-sha-path.el

diff --git a/doc/emacs.texi b/doc/emacs.texi
index 9e8fec4..427700e 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -18,6 +18,7 @@ guix package}).  Specifically, ``guix.el'' makes it easy to:
 * Initial Setup: Emacs Initial Setup.	Preparing @file{~/.emacs}.
 * Usage: Emacs Usage.			Using the interface.
 * Configuration: Emacs Configuration.	Configuring the interface.
+* Pretty SHA Path: Emacs Pretty Path.	Prettifying @file{/gnu/store/@dots{}} paths.
 @end menu
 
 @node Emacs Initial Setup
@@ -422,3 +423,43 @@ buffers.
 Various settings for ``info'' buffers.
 
 @end table
+
+
+@node Emacs Pretty Path
+@subsection Pretty SHA Path Mode
+
+Along with ``guix.el'', GNU@tie{}Guix comes with ``pretty-sha-path.el''.
+It provides a minor mode for abbreviating store paths by replacing
+SHA-sequences of symbols with ``@dots{}'':
+
+@example
+/gnu/store/onecansee32lettersandnumbershere-foo-0.1  @result{}  /gnu/store/…-foo-0.1
+@end example
+
+Once you set up ``guix.el'' (@pxref{Emacs Initial Setup}), the following
+commands become available:
+
+@table @kbd
+
+@item M-x pretty-sha-path-mode
+Enable/disable prettifying for the current buffer.
+
+@item M-x pretty-sha-path-global-mode
+Enable/disable prettifying globally.
+
+@end table
+
+To automatically enable @code{pretty-sha-path-mode} globally on Emacs
+start, add the following line to your init file:
+
+@example
+(pretty-sha-path-global-mode)
+@end example
+
+If you want to enable it only for specific major modes, add it to the
+mode hooks (@pxref{Hooks,,, emacs, The GNU Emacs Manual}), for example:
+
+@example
+(add-hook 'shell-mode-hook 'pretty-sha-path-mode)
+(add-hook 'dired-mode-hook 'pretty-sha-path-mode)
+@end example
diff --git a/emacs.am b/emacs.am
index 35470a3..dba0a0c 100644
--- a/emacs.am
+++ b/emacs.am
@@ -24,8 +24,10 @@ ELFILES =					\
   emacs/guix-history.el				\
   emacs/guix-info.el				\
   emacs/guix-list.el				\
+  emacs/guix-messages.el			\
   emacs/guix-utils.el				\
-  emacs/guix.el
+  emacs/guix.el					\
+  emacs/pretty-sha-path.el
 
 if HAVE_EMACS
 
diff --git a/emacs/pretty-sha-path.el b/emacs/pretty-sha-path.el
new file mode 100644
index 0000000..d991950
--- /dev/null
+++ b/emacs/pretty-sha-path.el
@@ -0,0 +1,200 @@
+;;; pretty-sha-path.el --- Prettify Guix store paths
+
+;; Copyright © 2014 Alex Kost <alezost@gmail.com>
+
+;; This file is part of GNU Guix.
+
+;; GNU Guix is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Guix is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package provides minor-mode for prettifying Guix/Nix store
+;; paths, i.e. after enabling `pretty-sha-path-mode',
+;; '/gnu/store/herewehavefancylettersandnumbers-foo-0.1' paths will be
+;; replaced with '/gnu/store/…-foo-0.1' paths in the current buffer.
+;; There is also `pretty-sha-path-global-mode' for global prettifying.
+
+;; To install, add the following to your emacs init file:
+;;
+;;   (add-to-list 'load-path "/path/to/pretty-sha-path")
+;;   (autoload 'pretty-sha-path-mode "pretty-sha-path" nil t)
+;;   (autoload 'pretty-sha-path-global-mode "pretty-sha-path" nil t)
+
+;; If you want to enable/disable composition after "M-x font-lock-mode",
+;; use the following setting:
+;;
+;;   (setq font-lock-extra-managed-props
+;;         (cons 'composition font-lock-extra-managed-props))
+
+;; Credits:
+;;
+;; Thanks to Ludovic Courtès for the idea of this package.
+;;
+;; Thanks to the authors of `prettify-symbols-mode' (part of Emacs 24.4)
+;; and "pretty-symbols.el" <http://github.com/drothlis/pretty-symbols>
+;; for the code.  It helped to write this package.
+
+;;; Code:
+
+(defgroup pretty-sha-path nil
+  "Prettify Guix/Nix store paths."
+  :prefix "pretty-sha-path-"
+  :group 'font-lock
+  :group 'convenience)
+
+(defcustom pretty-sha-path-char ?…
+  "Character used for prettifying."
+  :type 'character
+  :group 'pretty-sha-path)
+
+(defcustom pretty-sha-path-decompose-force nil
+  "If non-nil, remove any composition.
+
+By default, after disabling `pretty-sha-path-mode',
+compositions (prettifying paths with `pretty-sha-path-char') are
+removed only from strings matching `pretty-sha-path-regexp', so
+that compositions created by other modes are left untouched.
+
+Set this variable to non-nil, if you want to remove any
+composition unconditionally (like `prettify-symbols-mode' does).
+Most likely it will do no harm and will make the process of
+disabling `pretty-sha-path-mode' a little faster."
+  :type 'boolean
+  :group 'pretty-sha-path)
+
+(defcustom pretty-sha-path-regexp
+  (rx "/"
+      (or "nix" "gnu")
+      "/store/"
+      (group (= 32 alnum)))
+  "Regexp matching SHA paths.
+
+Disable `pretty-sha-path-mode' before modifying this variable and
+make sure to modify `pretty-sha-path-regexp-group' if needed.
+
+Example of a \"deeper\" prettifying:
+
+  (setq pretty-sha-path-regexp \"store/[[:alnum:]]\\\\\\={32\\\\}\"
+        pretty-sha-path-regexp-group 0)
+
+This will transform
+'/gnu/store/onecansee32lettersandnumbershere-foo-0.1' into
+'/gnu/…-foo-0.1'"
+  :type 'regexp
+  :group 'pretty-sha-path)
+
+(defcustom pretty-sha-path-regexp-group 1
+  "Regexp group in `pretty-sha-path-regexp' for prettifying."
+  :type 'integer
+  :group 'pretty-sha-path)
+
+(defvar pretty-sha-path-special-modes
+  '(guix-info-mode ibuffer-mode)
+  "List of special modes that support font-locking.
+
+By default, \\[pretty-sha-path-global-mode] enables prettifying
+in all buffers except the ones where `font-lock-defaults' is
+nil (see Info node `(elisp) Font Lock Basics'), because it may
+break the existing highlighting.
+
+Modes from this list and all derived modes are exceptions
+\(`pretty-sha-path-global-mode' enables prettifying there).")
+
+(defvar pretty-sha-path-flush-function
+  (cond ((fboundp 'font-lock-flush) #'font-lock-flush)
+        ((fboundp 'jit-lock-refontify) #'jit-lock-refontify))
+  "Function used to refontify buffer.
+This function is called without arguments after
+enabling/disabling `pretty-sha-path-mode'.
+If nil, do nothing.")
+
+(defun pretty-sha-path-compose ()
+  "Compose matching region in the current buffer."
+  (let ((beg (match-beginning pretty-sha-path-regexp-group))
+        (end (match-end       pretty-sha-path-regexp-group)))
+    (compose-region beg end pretty-sha-path-char 'decompose-region))
+  ;; Return nil because we're not adding any face property.
+  nil)
+
+(defun pretty-sha-path-decompose-buffer ()
+  "Remove path compositions from the current buffer."
+  (with-silent-modifications
+    (let ((inhibit-read-only t))
+      (if pretty-sha-path-decompose-force
+          (remove-text-properties (point-min)
+                                  (point-max)
+                                  '(composition nil))
+        (save-excursion
+          (goto-char (point-min))
+          (while (re-search-forward pretty-sha-path-regexp nil t)
+            (remove-text-properties
+             (match-beginning pretty-sha-path-regexp-group)
+             (match-end       pretty-sha-path-regexp-group)
+             '(composition nil))))))))
+
+;;;###autoload
+(define-minor-mode pretty-sha-path-mode
+  "Toggle Pretty SHA Path mode.
+
+With a prefix argument ARG, enable Pretty SHA Path mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+When Pretty SHA Path mode is enabled, SHA-parts of the Guix/Nix
+store paths (see `pretty-sha-path-regexp') are prettified,
+i.e. displayed as `pretty-sha-path-char' character.  This mode
+can be enabled programmatically using hooks:
+
+  (add-hook 'shell-mode-hook 'pretty-sha-path-mode)
+
+It is possible to enable the mode in any buffer, however not any
+buffer's highlighting may survive after adding new elements to
+`font-lock-keywords' (see `pretty-sha-path-special-modes' for
+details).
+
+Also you can use `pretty-sha-path-global-mode' to enable Pretty
+SHA Path mode for all modes that support font-locking."
+  :init-value nil
+  :lighter " …"
+  (let ((keywords `((,pretty-sha-path-regexp
+                     (,pretty-sha-path-regexp-group
+                      (pretty-sha-path-compose))))))
+    (if pretty-sha-path-mode
+        ;; Turn on.
+        (font-lock-add-keywords nil keywords)
+      ;; Turn off.
+      (font-lock-remove-keywords nil keywords)
+      (pretty-sha-path-decompose-buffer))
+    (and pretty-sha-path-flush-function
+         (funcall pretty-sha-path-flush-function))))
+
+(defun pretty-sha-path-supported-p ()
+  "Return non-nil, if the mode can be harmlessly enabled in current buffer."
+  (or font-lock-defaults
+      (apply #'derived-mode-p pretty-sha-path-special-modes)))
+
+(defun pretty-sha-path-turn-on ()
+  "Enable `pretty-sha-path-mode' in the current buffer if needed.
+See `pretty-sha-path-special-modes' for details."
+  (and (not pretty-sha-path-mode)
+       (pretty-sha-path-supported-p)
+       (pretty-sha-path-mode)))
+
+;;;###autoload
+(define-globalized-minor-mode pretty-sha-path-global-mode
+  pretty-sha-path-mode pretty-sha-path-turn-on)
+
+(provide 'pretty-sha-path)
+
+;;; pretty-sha-path.el ends here
-- 
2.1.2


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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-04 16:48 [PATCH] emacs: Add 'pretty-sha-path' Alex Kost
@ 2014-11-04 19:39 ` Mark H Weaver
  2014-11-05 11:24   ` Alex Kost
  2014-11-04 21:37 ` Ludovic Courtès
  1 sibling, 1 reply; 10+ messages in thread
From: Mark H Weaver @ 2014-11-04 19:39 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Hi Alex,

Alex Kost <alezost@gmail.com> writes:

> +(defcustom pretty-sha-path-regexp
> +  (rx "/"
> +      (or "nix" "gnu")
> +      "/store/"
> +      (group (= 32 alnum)))

I'm not sure if it's worth it, but you could make this regexp more
restrictive.  Nix hashes can only contain the following 32 characters:

  "0123456789abcdfghijklmnpqrsvwxyz"

i.e. digits and lowercase ASCII letters excluding (e o u t).  See
'base32Chars' in nix/libutil/hash.cc.

      Mark

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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-04 16:48 [PATCH] emacs: Add 'pretty-sha-path' Alex Kost
  2014-11-04 19:39 ` Mark H Weaver
@ 2014-11-04 21:37 ` Ludovic Courtès
  2014-11-05 11:24   ` Alex Kost
  1 sibling, 1 reply; 10+ messages in thread
From: Ludovic Courtès @ 2014-11-04 21:37 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Also I forgot to mention “emacs/guix-messages.el” in “emacs.am” in
> commit 62f261d, so I did it in this patch (I hope it's not too evil :-))

Maybe “evil” is too strong a word ;-), but please keep the
emacs/guix-messages.el addition in a separate commit.

Commits are cheap and easy, so let’s favor clarity.

> From e7ca6550d7f33d894e0023e3305938fce365fdba Mon Sep 17 00:00:00 2001
> From: Alex Kost <alezost@gmail.com>
> Date: Tue, 4 Nov 2014 19:38:27 +0300
> Subject: [PATCH] emacs: Add 'pretty-sha-path'.
>
> * emacs/pretty-sha-path.el: New file.
> * emacs.am (ELFILES): Add it.
> * doc/emacs.texi (Emacs Pretty Path): New node.

[...]

> +@node Emacs Pretty Path
> +@subsection Pretty SHA Path Mode

What about adding, at the end of the first paragraph of the “Features”
section, something like:

  ... where @code{xxx} is a base32 string (note that Guix comes with an
  Emacs extension to shorten those file names, @ref{Emacs Pretty Path}.)

> +Along with ``guix.el'', GNU@tie{}Guix comes with ``pretty-sha-path.el''.
> +It provides a minor mode for abbreviating store paths by replacing
> +SHA-sequences of symbols with ``@dots{}'':
> +
> +@example
> +/gnu/store/onecansee32lettersandnumbershere-foo-0.1  @result{}  /gnu/store/…-foo-0.1

Perhaps insert a line break before @result{}, otherwise the PDF output
may be truncated.

> +@item M-x pretty-sha-path-global-mode
> +Enable/disable prettifying globally.

It seemed to me that the convention would be to call it
global-pretty-sha-path-mode rather, no?

Other than that, LGTM!

Mark is right about refining the regexp, but OTOH false positives are
very unlikely, and it might make things slightly slower, no?  So either
way is fine with me.

Thanks!

Ludo’.

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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-04 19:39 ` Mark H Weaver
@ 2014-11-05 11:24   ` Alex Kost
  0 siblings, 0 replies; 10+ messages in thread
From: Alex Kost @ 2014-11-05 11:24 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guix-devel

Mark H Weaver (2014-11-04 22:39 +0300) wrote:

> Hi Alex,
>
> Alex Kost <alezost@gmail.com> writes:
>
>> +(defcustom pretty-sha-path-regexp
>> +  (rx "/"
>> +      (or "nix" "gnu")
>> +      "/store/"
>> +      (group (= 32 alnum)))
>
> I'm not sure if it's worth it, but you could make this regexp more
> restrictive.  Nix hashes can only contain the following 32 characters:
>
>   "0123456789abcdfghijklmnpqrsvwxyz"
>
> i.e. digits and lowercase ASCII letters excluding (e o u t).  See
> 'base32Chars' in nix/libutil/hash.cc.

Oh, I didn't know that, thank you for the information; I will adjust the
regexp.

-- 
Alex

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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-04 21:37 ` Ludovic Courtès
@ 2014-11-05 11:24   ` Alex Kost
  2014-11-05 20:12     ` Ludovic Courtès
  0 siblings, 1 reply; 10+ messages in thread
From: Alex Kost @ 2014-11-05 11:24 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Ludovic Courtès (2014-11-05 00:37 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> Also I forgot to mention “emacs/guix-messages.el” in “emacs.am” in
>> commit 62f261d, so I did it in this patch (I hope it's not too evil :-))
>
> Maybe “evil” is too strong a word ;-), but please keep the
> emacs/guix-messages.el addition in a separate commit.
>
> Commits are cheap and easy, so let’s favor clarity.

Yes, cheap, I know, but not very easy for me as I never sure what to
write in a commit message and I have to ask guix-devel even about such
trivial changes (the patch is attached :-)).

>> From e7ca6550d7f33d894e0023e3305938fce365fdba Mon Sep 17 00:00:00 2001
>> From: Alex Kost <alezost@gmail.com>
>> Date: Tue, 4 Nov 2014 19:38:27 +0300
>> Subject: [PATCH] emacs: Add 'pretty-sha-path'.
>>
>> * emacs/pretty-sha-path.el: New file.
>> * emacs.am (ELFILES): Add it.
>> * doc/emacs.texi (Emacs Pretty Path): New node.
>
> [...]
>
>> +@node Emacs Pretty Path
>> +@subsection Pretty SHA Path Mode
>
> What about adding, at the end of the first paragraph of the “Features”
> section, something like:
>
>   ... where @code{xxx} is a base32 string (note that Guix comes with an
>   Emacs extension to shorten those file names, @ref{Emacs Pretty Path}.)

OK, will do.

>> +Along with ``guix.el'', GNU@tie{}Guix comes with ``pretty-sha-path.el''.
>> +It provides a minor mode for abbreviating store paths by replacing
>> +SHA-sequences of symbols with ``@dots{}'':
>> +
>> +@example
>> +/gnu/store/onecansee32lettersandnumbershere-foo-0.1  @result{}  /gnu/store/…-foo-0.1
>
> Perhaps insert a line break before @result{}, otherwise the PDF output
> may be truncated.

OK.

>> +@item M-x pretty-sha-path-global-mode
>> +Enable/disable prettifying globally.
>
> It seemed to me that the convention would be to call it
> global-pretty-sha-path-mode rather, no?

Ah, thanks!  I didn't thought about that; I just always used a package
prefix for all symbols.

According to (info "(elisp) Coding Conventions"):

--8<---------------cut here---------------start------------->8---
   • You should choose a short word to distinguish your program from
     other Lisp programs.  The names of all global symbols in your
     program, that is the names of variables, constants, and functions,
     should begin with that chosen prefix.  Separate the prefix from the
     rest of the name with a hyphen, ‘-’.  This practice helps avoid
     name conflicts, since all global variables in Emacs Lisp share the
     same name space, and all functions share another name space(1).
--8<---------------cut here---------------end--------------->8---

And also:

--8<---------------cut here---------------start------------->8---
     Occasionally, for a command name intended for users to use, it is
     more convenient if some words come before the package’s name
     prefix.
--8<---------------cut here---------------end--------------->8---

So I'm going to add ‘global-pretty-sha-path-mode’ and mention it in the
documentation, but I also leave ‘pretty-sha-path-global-mode’ just in
case (I'll make it an alias).

> Other than that, LGTM!
>
> Mark is right about refining the regexp, but OTOH false positives are
> very unlikely, and it might make things slightly slower, no?  So either
> way is fine with me.

I think it shouldn't be visibly slower.

I've realized that "pretty-sha-path" is a bad name, because those 32
numbers and letters have nothing to do with SHA-sequences as I thought
initially.  So maybe it would be better to rename it into
"pretty-hash-path" or "guix-pretty-path" (as it will be a part of Guix)
or something else.  Or is it OK to leave it as it is?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-build-Add-missing-emacs-guix-messages.el.patch --]
[-- Type: text/x-diff, Size: 611 bytes --]

From 4648af5bab6a9e98cc4c725b8fcca159874d4380 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Wed, 5 Nov 2014 14:00:05 +0300
Subject: [PATCH] build: Add missing "emacs/guix-messages.el".

* emacs.am (ELFILES): Add "emacs/guix-messages.el".
---
 emacs.am | 1 +
 1 file changed, 1 insertion(+)

diff --git a/emacs.am b/emacs.am
index 35470a3..9279078 100644
--- a/emacs.am
+++ b/emacs.am
@@ -24,6 +24,7 @@ ELFILES =					\
   emacs/guix-history.el				\
   emacs/guix-info.el				\
   emacs/guix-list.el				\
+  emacs/guix-messages.el			\
   emacs/guix-utils.el				\
   emacs/guix.el
 
-- 
2.1.2


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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-05 11:24   ` Alex Kost
@ 2014-11-05 20:12     ` Ludovic Courtès
  2014-11-05 21:38       ` Alex Kost
  0 siblings, 1 reply; 10+ messages in thread
From: Ludovic Courtès @ 2014-11-05 20:12 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Ludovic Courtès (2014-11-05 00:37 +0300) wrote:
>
>> Alex Kost <alezost@gmail.com> skribis:
>>
>>> Also I forgot to mention “emacs/guix-messages.el” in “emacs.am” in
>>> commit 62f261d, so I did it in this patch (I hope it's not too evil :-))
>>
>> Maybe “evil” is too strong a word ;-), but please keep the
>> emacs/guix-messages.el addition in a separate commit.
>>
>> Commits are cheap and easy, so let’s favor clarity.
>
> Yes, cheap, I know, but not very easy for me as I never sure what to
> write in a commit message and I have to ask guix-devel even about such
> trivial changes (the patch is attached :-)).

Per ‘HACKING’ ;-), you don’t *have* to ask for trivial changes.  It’s
nice of you to do it, but you don’t have to.

IMO it’s time to formalize maintainership and responsibilities, as I had
proposed a while back.  I’ll get back to it.

> So I'm going to add ‘global-pretty-sha-path-mode’ and mention it in the
> documentation, but I also leave ‘pretty-sha-path-global-mode’ just in
> case (I'll make it an alias).

Sounds good.

> I've realized that "pretty-sha-path" is a bad name, because those 32
> numbers and letters have nothing to do with SHA-sequences as I thought
> initially.  So maybe it would be better to rename it into
> "pretty-hash-path" or "guix-pretty-path" (as it will be a part of Guix)
> or something else.  Or is it OK to leave it as it is?

Good point.  Prefixing with ‘guix-’ makes sense, and it will be easier
for users to find it.

While we’re at it, “path” in GNU normally means “search path”, not “file
name” (info "(standards) GNU Manuals"), so perhaps
‘guix-pretty-file-names’ or something like that would be even better.
WDYT?

(Yes, (guix store) still uses the “store path” terminology inherited
from Nix.)

> From 4648af5bab6a9e98cc4c725b8fcca159874d4380 Mon Sep 17 00:00:00 2001
> From: Alex Kost <alezost@gmail.com>
> Date: Wed, 5 Nov 2014 14:00:05 +0300
> Subject: [PATCH] build: Add missing "emacs/guix-messages.el".
>
> * emacs.am (ELFILES): Add "emacs/guix-messages.el".

OK for this one, of course.  :-)

Ludo’.

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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-05 20:12     ` Ludovic Courtès
@ 2014-11-05 21:38       ` Alex Kost
  2014-11-06  9:37         ` Ludovic Courtès
  0 siblings, 1 reply; 10+ messages in thread
From: Alex Kost @ 2014-11-05 21:38 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

Ludovic Courtès (2014-11-05 23:12 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> Ludovic Courtès (2014-11-05 00:37 +0300) wrote:
>>
>>> Alex Kost <alezost@gmail.com> skribis:
>>>
>>>> Also I forgot to mention “emacs/guix-messages.el” in “emacs.am” in
>>>> commit 62f261d, so I did it in this patch (I hope it's not too evil :-))
>>>
>>> Maybe “evil” is too strong a word ;-), but please keep the
>>> emacs/guix-messages.el addition in a separate commit.
>>>
>>> Commits are cheap and easy, so let’s favor clarity.
>>
>> Yes, cheap, I know, but not very easy for me as I never sure what to
>> write in a commit message and I have to ask guix-devel even about such
>> trivial changes (the patch is attached :-)).
>
> Per ‘HACKING’ ;-), you don’t *have* to ask for trivial changes.  It’s
> nice of you to do it, but you don’t have to.

Yes, I know, I meant I'm not sure if my commit messages will be
appropriate.

[...]

>> I've realized that "pretty-sha-path" is a bad name, because those 32
>> numbers and letters have nothing to do with SHA-sequences as I thought
>> initially.  So maybe it would be better to rename it into
>> "pretty-hash-path" or "guix-pretty-path" (as it will be a part of Guix)
>> or something else.  Or is it OK to leave it as it is?
>
> Good point.  Prefixing with ‘guix-’ makes sense, and it will be easier
> for users to find it.
>
> While we’re at it, “path” in GNU normally means “search path”, not “file
> name” (info "(standards) GNU Manuals"), so perhaps
> ‘guix-pretty-file-names’ or something like that would be even better.
> WDYT?

I think ‘guix-pretty-file-names’ is too long for a package name as all
symbols have to be prefixed with it.  What about ‘guix-prettify’?

-- 
Alex

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

* Re: [PATCH] emacs: Add 'pretty-sha-path'.
  2014-11-05 21:38       ` Alex Kost
@ 2014-11-06  9:37         ` Ludovic Courtès
  2014-11-06 13:13           ` [PATCH] emacs: Add 'guix-prettify' Alex Kost
  0 siblings, 1 reply; 10+ messages in thread
From: Ludovic Courtès @ 2014-11-06  9:37 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Ludovic Courtès (2014-11-05 23:12 +0300) wrote:
>
>> Alex Kost <alezost@gmail.com> skribis:
>>
>>> Ludovic Courtès (2014-11-05 00:37 +0300) wrote:
>>>
>>>> Alex Kost <alezost@gmail.com> skribis:
>>>>
>>>>> Also I forgot to mention “emacs/guix-messages.el” in “emacs.am” in
>>>>> commit 62f261d, so I did it in this patch (I hope it's not too evil :-))
>>>>
>>>> Maybe “evil” is too strong a word ;-), but please keep the
>>>> emacs/guix-messages.el addition in a separate commit.
>>>>
>>>> Commits are cheap and easy, so let’s favor clarity.
>>>
>>> Yes, cheap, I know, but not very easy for me as I never sure what to
>>> write in a commit message and I have to ask guix-devel even about such
>>> trivial changes (the patch is attached :-)).
>>
>> Per ‘HACKING’ ;-), you don’t *have* to ask for trivial changes.  It’s
>> nice of you to do it, but you don’t have to.
>
> Yes, I know, I meant I'm not sure if my commit messages will be
> appropriate.

Oh, I see.  I think it’s not all good-or-bad, and it’s not the end of
the world if the commit message isn’t perfect.  So we must make some
efforts to achieve consistency and follow our own guidelines, but that
must not block the more important effort of developing the software.

>>> I've realized that "pretty-sha-path" is a bad name, because those 32
>>> numbers and letters have nothing to do with SHA-sequences as I thought
>>> initially.  So maybe it would be better to rename it into
>>> "pretty-hash-path" or "guix-pretty-path" (as it will be a part of Guix)
>>> or something else.  Or is it OK to leave it as it is?
>>
>> Good point.  Prefixing with ‘guix-’ makes sense, and it will be easier
>> for users to find it.
>>
>> While we’re at it, “path” in GNU normally means “search path”, not “file
>> name” (info "(standards) GNU Manuals"), so perhaps
>> ‘guix-pretty-file-names’ or something like that would be even better.
>> WDYT?
>
> I think ‘guix-pretty-file-names’ is too long for a package name as all
> symbols have to be prefixed with it.  What about ‘guix-prettify’?

OK!

Ludo’.

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

* [PATCH] emacs: Add 'guix-prettify'.
  2014-11-06  9:37         ` Ludovic Courtès
@ 2014-11-06 13:13           ` Alex Kost
  2014-11-06 16:05             ` Ludovic Courtès
  0 siblings, 1 reply; 10+ messages in thread
From: Alex Kost @ 2014-11-06 13:13 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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

Ludovic Courtès (2014-11-06 12:37 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> Ludovic Courtès (2014-11-05 23:12 +0300) wrote:
>>
>>> Alex Kost <alezost@gmail.com> skribis:
[...]
>>>> I've realized that "pretty-sha-path" is a bad name, because those 32
>>>> numbers and letters have nothing to do with SHA-sequences as I thought
>>>> initially.  So maybe it would be better to rename it into
>>>> "pretty-hash-path" or "guix-pretty-path" (as it will be a part of Guix)
>>>> or something else.  Or is it OK to leave it as it is?
>>>
>>> Good point.  Prefixing with ‘guix-’ makes sense, and it will be easier
>>> for users to find it.
>>>
>>> While we’re at it, “path” in GNU normally means “search path”, not “file
>>> name” (info "(standards) GNU Manuals"), so perhaps
>>> ‘guix-pretty-file-names’ or something like that would be even better.
>>> WDYT?
>>
>> I think ‘guix-pretty-file-names’ is too long for a package name as all
>> symbols have to be prefixed with it.  What about ‘guix-prettify’?
>
> OK!

Thanks, here is the patch again: the package was renamed; regexp was
corrected; a reference in “guix.texi” was made and "path"-s were
replaced by "file name"-s.  It's still not too late to rename everything
if ‘guix-prettify’ looks unsatisfactory.


[-- Attachment #2: 0001-emacs-Add-guix-prettify.patch --]
[-- Type: text/x-diff, Size: 11340 bytes --]

From e074a41a5a96d4b3a4c6e5dbb4f11993b500b429 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Tue, 4 Nov 2014 19:38:27 +0300
Subject: [PATCH] emacs: Add 'guix-prettify'.

* emacs/guix-prettify.el: New file.
* emacs.am (ELFILES): Add it.
* doc/emacs.texi (Emacs Prettify): New node.
* doc/guix.texi (Features): Mention it.
---
 doc/emacs.texi         |  42 ++++++++++
 doc/guix.texi          |   4 +-
 emacs.am               |   1 +
 emacs/guix-prettify.el | 204 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 250 insertions(+), 1 deletion(-)
 create mode 100644 emacs/guix-prettify.el

diff --git a/doc/emacs.texi b/doc/emacs.texi
index 9e8fec4..89e2570 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -18,6 +18,7 @@ guix package}).  Specifically, ``guix.el'' makes it easy to:
 * Initial Setup: Emacs Initial Setup.	Preparing @file{~/.emacs}.
 * Usage: Emacs Usage.			Using the interface.
 * Configuration: Emacs Configuration.	Configuring the interface.
+* Prettify Mode: Emacs Prettify.	Abbreviating @file{/gnu/store/@dots{}} file names.
 @end menu
 
 @node Emacs Initial Setup
@@ -422,3 +423,44 @@ buffers.
 Various settings for ``info'' buffers.
 
 @end table
+
+
+@node Emacs Prettify
+@subsection Guix Prettify Mode
+
+Along with ``guix.el'', GNU@tie{}Guix comes with ``guix-prettify.el''.
+It provides a minor mode for abbreviating store file names by replacing
+hash sequences of symbols with ``@dots{}'':
+
+@example
+/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1
+@result{} /gnu/store/…-foo-0.1
+@end example
+
+Once you set up ``guix.el'' (@pxref{Emacs Initial Setup}), the following
+commands become available:
+
+@table @kbd
+
+@item M-x guix-prettify-mode
+Enable/disable prettifying for the current buffer.
+
+@item M-x global-guix-prettify-mode
+Enable/disable prettifying globally.
+
+@end table
+
+To automatically enable @code{guix-prettify-mode} globally on Emacs
+start, add the following line to your init file:
+
+@example
+(global-guix-prettify-mode)
+@end example
+
+If you want to enable it only for specific major modes, add it to the
+mode hooks (@pxref{Hooks,,, emacs, The GNU Emacs Manual}), for example:
+
+@example
+(add-hook 'shell-mode-hook 'guix-prettify-mode)
+(add-hook 'dired-mode-hook 'guix-prettify-mode)
+@end example
diff --git a/doc/guix.texi b/doc/guix.texi
index 4a596bc..35fe27f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -628,7 +628,9 @@ management tools it provides.
 
 When using Guix, each package ends up in the @dfn{package store}, in its
 own directory---something that resembles
-@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
+@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
+(note that Guix comes with an Emacs extension to shorten those file
+names, @ref{Emacs Prettify}.)
 
 Instead of referring to these directories, users have their own
 @dfn{profile}, which points to the packages that they actually want to
diff --git a/emacs.am b/emacs.am
index 9279078..be7e77e 100644
--- a/emacs.am
+++ b/emacs.am
@@ -25,6 +25,7 @@ ELFILES =					\
   emacs/guix-info.el				\
   emacs/guix-list.el				\
   emacs/guix-messages.el			\
+  emacs/guix-prettify.el			\
   emacs/guix-utils.el				\
   emacs/guix.el
 
diff --git a/emacs/guix-prettify.el b/emacs/guix-prettify.el
new file mode 100644
index 0000000..b01495c
--- /dev/null
+++ b/emacs/guix-prettify.el
@@ -0,0 +1,204 @@
+;;; guix-prettify.el --- Prettify Guix store file names
+
+;; Copyright © 2014 Alex Kost <alezost@gmail.com>
+
+;; This file is part of GNU Guix.
+
+;; GNU Guix is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Guix is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package provides minor-mode for prettifying Guix store file
+;; names — i.e., after enabling `guix-prettify-mode',
+;; '/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1' names will be
+;; replaced with '/gnu/store/…-foo-0.1' in the current buffer.  There is
+;; also `global-guix-prettify-mode' for global prettifying.
+
+;; To install, add the following to your emacs init file:
+;;
+;;   (add-to-list 'load-path "/path/to/dir-with-guix-prettify")
+;;   (autoload 'guix-prettify-mode "guix-prettify" nil t)
+;;   (autoload 'global-guix-prettify-mode "guix-prettify" nil t)
+
+;; If you want to enable/disable composition after "M-x font-lock-mode",
+;; use the following setting:
+;;
+;;   (setq font-lock-extra-managed-props
+;;         (cons 'composition font-lock-extra-managed-props))
+
+;; Credits:
+;;
+;; Thanks to Ludovic Courtès for the idea of this package.
+;;
+;; Thanks to the authors of `prettify-symbols-mode' (part of Emacs 24.4)
+;; and "pretty-symbols.el" <http://github.com/drothlis/pretty-symbols>
+;; for the code.  It helped to write this package.
+
+;;; Code:
+
+(defgroup guix-prettify nil
+  "Prettify Guix store file names."
+  :prefix "guix-prettify-"
+  :group 'font-lock
+  :group 'convenience)
+
+(defcustom guix-prettify-char ?…
+  "Character used for prettifying."
+  :type 'character
+  :group 'guix-prettify)
+
+(defcustom guix-prettify-decompose-force nil
+  "If non-nil, remove any composition.
+
+By default, after disabling `guix-prettify-mode',
+compositions (prettifying names with `guix-prettify-char') are
+removed only from strings matching `guix-prettify-regexp', so
+that compositions created by other modes are left untouched.
+
+Set this variable to non-nil, if you want to remove any
+composition unconditionally (like `prettify-symbols-mode' does).
+Most likely it will do no harm and will make the process of
+disabling `guix-prettify-mode' a little faster."
+  :type 'boolean
+  :group 'guix-prettify)
+
+(defcustom guix-prettify-regexp
+  (rx "/"
+      (or "nix" "gnu")
+      "/store/"
+      ;; Hash-parts do not include "e", "o", "u" and "t".  See base32Chars
+      ;; at <https://github.com/NixOS/nix/blob/master/src/libutil/hash.cc>
+      (group (= 32 (any "0-9" "a-d" "f-n" "p-s" "v-z"))))
+  "Regexp matching file names for prettifying.
+
+Disable `guix-prettify-mode' before modifying this variable and
+make sure to modify `guix-prettify-regexp-group' if needed.
+
+Example of a \"deeper\" prettifying:
+
+  (setq guix-prettify-regexp \"store/[[:alnum:]]\\\\\\={32\\\\}\"
+        guix-prettify-regexp-group 0)
+
+This will transform
+'/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1' into
+'/gnu/…-foo-0.1'"
+  :type 'regexp
+  :group 'guix-prettify)
+
+(defcustom guix-prettify-regexp-group 1
+  "Regexp group in `guix-prettify-regexp' for prettifying."
+  :type 'integer
+  :group 'guix-prettify)
+
+(defvar guix-prettify-special-modes
+  '(guix-info-mode ibuffer-mode)
+  "List of special modes that support font-locking.
+
+By default, \\[global-guix-prettify-mode] enables prettifying in
+all buffers except the ones where `font-lock-defaults' is
+nil (see Info node `(elisp) Font Lock Basics'), because it may
+break the existing highlighting.
+
+Modes from this list and all derived modes are exceptions
+\(`global-guix-prettify-mode' enables prettifying there).")
+
+(defvar guix-prettify-flush-function
+  (cond ((fboundp 'font-lock-flush) #'font-lock-flush)
+        ((fboundp 'jit-lock-refontify) #'jit-lock-refontify))
+  "Function used to refontify buffer.
+This function is called without arguments after
+enabling/disabling `guix-prettify-mode'.  If nil, do nothing.")
+
+(defun guix-prettify-compose ()
+  "Compose matching region in the current buffer."
+  (let ((beg (match-beginning guix-prettify-regexp-group))
+        (end (match-end       guix-prettify-regexp-group)))
+    (compose-region beg end guix-prettify-char 'decompose-region))
+  ;; Return nil because we're not adding any face property.
+  nil)
+
+(defun guix-prettify-decompose-buffer ()
+  "Remove file names compositions from the current buffer."
+  (with-silent-modifications
+    (let ((inhibit-read-only t))
+      (if guix-prettify-decompose-force
+          (remove-text-properties (point-min)
+                                  (point-max)
+                                  '(composition nil))
+        (save-excursion
+          (goto-char (point-min))
+          (while (re-search-forward guix-prettify-regexp nil t)
+            (remove-text-properties
+             (match-beginning guix-prettify-regexp-group)
+             (match-end       guix-prettify-regexp-group)
+             '(composition nil))))))))
+
+;;;###autoload
+(define-minor-mode guix-prettify-mode
+  "Toggle Guix Prettify mode.
+
+With a prefix argument ARG, enable Guix Prettify mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+When Guix Prettify mode is enabled, hash-parts of the Guix store
+file names (see `guix-prettify-regexp') are prettified,
+i.e. displayed as `guix-prettify-char' character.  This mode can
+be enabled programmatically using hooks:
+
+  (add-hook 'shell-mode-hook 'guix-prettify-mode)
+
+It is possible to enable the mode in any buffer, however not any
+buffer's highlighting may survive after adding new elements to
+`font-lock-keywords' (see `guix-prettify-special-modes' for
+details).
+
+Also you can use `global-guix-prettify-mode' to enable Guix
+Prettify mode for all modes that support font-locking."
+  :init-value nil
+  :lighter " …"
+  (let ((keywords `((,guix-prettify-regexp
+                     (,guix-prettify-regexp-group
+                      (guix-prettify-compose))))))
+    (if guix-prettify-mode
+        ;; Turn on.
+        (font-lock-add-keywords nil keywords)
+      ;; Turn off.
+      (font-lock-remove-keywords nil keywords)
+      (guix-prettify-decompose-buffer))
+    (and guix-prettify-flush-function
+         (funcall guix-prettify-flush-function))))
+
+(defun guix-prettify-supported-p ()
+  "Return non-nil, if the mode can be harmlessly enabled in current buffer."
+  (or font-lock-defaults
+      (apply #'derived-mode-p guix-prettify-special-modes)))
+
+(defun guix-prettify-turn-on ()
+  "Enable `guix-prettify-mode' in the current buffer if needed.
+See `guix-prettify-special-modes' for details."
+  (and (not guix-prettify-mode)
+       (guix-prettify-supported-p)
+       (guix-prettify-mode)))
+
+;;;###autoload
+(define-globalized-minor-mode global-guix-prettify-mode
+  guix-prettify-mode guix-prettify-turn-on)
+
+;;;###autoload
+(defalias 'guix-prettify-global-mode 'global-guix-prettify-mode)
+
+(provide 'guix-prettify)
+
+;;; guix-prettify.el ends here
-- 
2.1.2


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

* Re: [PATCH] emacs: Add 'guix-prettify'.
  2014-11-06 13:13           ` [PATCH] emacs: Add 'guix-prettify' Alex Kost
@ 2014-11-06 16:05             ` Ludovic Courtès
  0 siblings, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2014-11-06 16:05 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Thanks, here is the patch again: the package was renamed; regexp was
> corrected; a reference in “guix.texi” was made and "path"-s were
> replaced by "file name"-s.  It's still not too late to rename everything
> if ‘guix-prettify’ looks unsatisfactory.

Perfect.

> From e074a41a5a96d4b3a4c6e5dbb4f11993b500b429 Mon Sep 17 00:00:00 2001
> From: Alex Kost <alezost@gmail.com>
> Date: Tue, 4 Nov 2014 19:38:27 +0300
> Subject: [PATCH] emacs: Add 'guix-prettify'.
>
> * emacs/guix-prettify.el: New file.
> * emacs.am (ELFILES): Add it.
> * doc/emacs.texi (Emacs Prettify): New node.
> * doc/guix.texi (Features): Mention it.

LGTM!

Thanks for your patience,
Ludo’.

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

end of thread, other threads:[~2014-11-06 16:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-04 16:48 [PATCH] emacs: Add 'pretty-sha-path' Alex Kost
2014-11-04 19:39 ` Mark H Weaver
2014-11-05 11:24   ` Alex Kost
2014-11-04 21:37 ` Ludovic Courtès
2014-11-05 11:24   ` Alex Kost
2014-11-05 20:12     ` Ludovic Courtès
2014-11-05 21:38       ` Alex Kost
2014-11-06  9:37         ` Ludovic Courtès
2014-11-06 13:13           ` [PATCH] emacs: Add 'guix-prettify' Alex Kost
2014-11-06 16:05             ` 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).