all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* indent with emacs batch mode
@ 2017-01-06 15:29 Ricardo Wurmus
  2017-01-07  5:59 ` Alex Kost
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Wurmus @ 2017-01-06 15:29 UTC (permalink / raw)
  To: guix-devel

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

Hi Guix,

here’s how people who don’t use Emacs can indent package expressions
nicely.

Save this file somewhere:


[-- Attachment #2: indent-package-expr.el --]
[-- Type: application/emacs-lisp, Size: 288 bytes --]

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


Enter an environment where Emacs and emacs-guix are available:

    guix environment --ad-hoc emacs emacs-guix

Then run:

    emacs -q --batch -l indent-package-expr.el  bowtie bla blast+

This will properly indent the package expressions for “bowtie” and
“blast+”, and it will ignore “bla”, because that package doesn’t exist.

This is probably a little heavy-weight because it depends on emacs-guix,
which starts a Guile REPL, but other than that it seems to work fine.

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
http://elephly.net

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

* Re: indent with emacs batch mode
  2017-01-06 15:29 indent with emacs batch mode Ricardo Wurmus
@ 2017-01-07  5:59 ` Alex Kost
  2017-01-07  7:25   ` Ricardo Wurmus
  2017-01-07 21:17   ` Ludovic Courtès
  0 siblings, 2 replies; 9+ messages in thread
From: Alex Kost @ 2017-01-07  5:59 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

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

Ricardo Wurmus (2017-01-06 16:29 +0100) wrote:

> Hi Guix,
>
> here’s how people who don’t use Emacs can indent package expressions
> nicely.

Interesting idea!

> Save this file somewhere:
>
> ;; indent expression for given packages

I would also add the following line here:

  (add-hook 'scheme-mode-hook 'guix-devel-mode)

to add Guix-specific indentation rules (particularly to indent
'modify-phases' properly).

> (require 'guix-location)
> (dolist (name command-line-args-left)
>   (let ((location (guix-package-location name)))
>     (when location
>       (guix-find-location location)
>       (beginning-of-defun)
>       (indent-sexp)
>       (save-buffer))))

I think this works for you because your "~/.config/guix/latest" is a
symlink to your git checkout.  But by default this can open a package
file from store, and emacs will fail to modify it, so it is better to
specify a guix checkout directory explicitly like this:

  (guix-find-location location "~/src/guix")

> Enter an environment where Emacs and emacs-guix are available:
>
>     guix environment --ad-hoc emacs emacs-guix
>
> Then run:
>
>     emacs -q --batch -l indent-package-expr.el  bowtie bla blast+

Actually this works for you only by chance: emacs doesn't load packages
from the guix environment, it loads packages from your system and user
profiles, so it works because you already have 'emacs-guix' installed.

> This will properly indent the package expressions for “bowtie” and
> “blast+”, and it will ignore “bla”, because that package doesn’t exist.
>
> This is probably a little heavy-weight because it depends on emacs-guix,
> which starts a Guile REPL, but other than that it seems to work fine.

Since a user knows what file (s)he wants modify, I think it is better to
avoid starting the REPL, so it will be *much faster*.  After all, I
would do it like this:


[-- Attachment #2: indent-package-expr.el --]
[-- Type: application/emacs-lisp, Size: 909 bytes --]

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


And here are the lines for the environment and running emacs (I used
'emacs-no-x' as it is not so heavy as 'emacs'):

  guix environment --ad-hoc emacs-no-x emacs-guix

  emacs -q --no-site-file --batch -l indent-package-expr.el /path/to/package-file.scm package-name

All that stuff can work without 'emacs-guix' (if the line with
'guix-devel-mode' scheme hook will be removed), but in this case the
package may not be indented properly.

-- 
Alex

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

* Re: indent with emacs batch mode
  2017-01-07  5:59 ` Alex Kost
@ 2017-01-07  7:25   ` Ricardo Wurmus
  2017-01-08 13:32     ` Alex Kost
  2017-01-07 21:17   ` Ludovic Courtès
  1 sibling, 1 reply; 9+ messages in thread
From: Ricardo Wurmus @ 2017-01-07  7:25 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel


Hi Alex,

I’m glad that my public display of my lack of skill with Emacs batch
mode has prompted you to come up with a much nicer solution that
actually works :)

My first version actually did use “re-search-forward” and required the
user to input both file name and package variable.  I had hoped to
simplify this a little by using “guix-location”.

> And here are the lines for the environment and running emacs (I used
> 'emacs-no-x' as it is not so heavy as 'emacs'):
>
>   guix environment --ad-hoc emacs-no-x emacs-guix
>
>   emacs -q --no-site-file --batch -l indent-package-expr.el /path/to/package-file.scm package-name

Thanks for the code and the example invocation!

> All that stuff can work without 'emacs-guix' (if the line with
> 'guix-devel-mode' scheme hook will be removed), but in this case the
> package may not be indented properly.

Guix still comes with a “.dir-locals.el” that specifies the indentation
rules, doesn’t it?  Can we use that?

-- 
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
http://elephly.net

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

* Re: indent with emacs batch mode
  2017-01-07  5:59 ` Alex Kost
  2017-01-07  7:25   ` Ricardo Wurmus
@ 2017-01-07 21:17   ` Ludovic Courtès
  2017-01-07 21:21     ` Ricardo Wurmus
  1 sibling, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2017-01-07 21:17 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Hi!

Alex Kost <alezost@gmail.com> skribis:

> Since a user knows what file (s)he wants modify, I think it is better to
> avoid starting the REPL, so it will be *much faster*.  After all, I
> would do it like this:

Sounds cool!  (The only downside is that it would indent the whole file
so the submitter might have to undo indentation changes in other parts
of the file before committing.)

What about committing it as a script, say
etc/devel/indent-scheme-code.sh, and mention it under “Submitting
Patches” and “Formatting Code”?

I’m sure many would find it helpful.

Thanks!

Ludo’.

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

* Re: indent with emacs batch mode
  2017-01-07 21:17   ` Ludovic Courtès
@ 2017-01-07 21:21     ` Ricardo Wurmus
  2017-01-08 13:48       ` Alex Kost
  0 siblings, 1 reply; 9+ messages in thread
From: Ricardo Wurmus @ 2017-01-07 21:21 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, Alex Kost


Ludovic Courtès <ludo@gnu.org> writes:

> Alex Kost <alezost@gmail.com> skribis:
>
>> Since a user knows what file (s)he wants modify, I think it is better to
>> avoid starting the REPL, so it will be *much faster*.  After all, I
>> would do it like this:
>
> Sounds cool!  (The only downside is that it would indent the whole file
> so the submitter might have to undo indentation changes in other parts
> of the file before committing.)

But we’re using “indent-sexp”, which only indents the expression that
belongs to the matched package name.

> What about committing it as a script, say
> etc/devel/indent-scheme-code.sh, and mention it under “Submitting
> Patches” and “Formatting Code”?

Sounds good to me.  Alex, would you like to do it?

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
http://elephly.net

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

* Re: indent with emacs batch mode
  2017-01-07  7:25   ` Ricardo Wurmus
@ 2017-01-08 13:32     ` Alex Kost
  2017-01-12 14:01       ` Ludovic Courtès
  0 siblings, 1 reply; 9+ messages in thread
From: Alex Kost @ 2017-01-08 13:32 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

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

Ricardo Wurmus (2017-01-07 08:25 +0100) wrote:

> Alex Kost wrote:
>
>> All that stuff can work without 'emacs-guix' (if the line with
>> 'guix-devel-mode' scheme hook will be removed), but in this case the
>> package may not be indented properly.
>
> Guix still comes with a “.dir-locals.el” that specifies the indentation
> rules, doesn’t it?  Can we use that?

Oof, it took me some time to figure it out :-)

So here is the version that requires only emacs and ".dir-locals.el"
file from the git repo:


[-- Attachment #2: indent-package-expr.el --]
[-- Type: application/emacs-lisp, Size: 751 bytes --]

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


Emacs can be run like this:

  emacs -Q --batch -l indent-package-expr.el package-file.scm package-name

The only downside of ".dir-locals.el", is that it doesn't contain
indentation rules for 'modify-phases' keywords (replace, add-after,
add-before).  Maybe they should be added there, but OTOH "replace" looks
like a too general name, so if a user has some code with "replace"
procedure, (s)he wouldn't be pleased when it will be indented strangely.
That's why "guix-devel.el" has a code that indents these keywords only
when they are inside 'modify-phases'.

-- 
Alex

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

* Re: indent with emacs batch mode
  2017-01-07 21:21     ` Ricardo Wurmus
@ 2017-01-08 13:48       ` Alex Kost
  0 siblings, 0 replies; 9+ messages in thread
From: Alex Kost @ 2017-01-08 13:48 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Ricardo Wurmus (2017-01-07 22:21 +0100) wrote:

> Ludovic Courtès <ludo@gnu.org> writes:
>
>> Alex Kost <alezost@gmail.com> skribis:
>>
>>> Since a user knows what file (s)he wants modify, I think it is better to
>>> avoid starting the REPL, so it will be *much faster*.  After all, I
>>> would do it like this:
>>
>> Sounds cool!  (The only downside is that it would indent the whole file
>> so the submitter might have to undo indentation changes in other parts
>> of the file before committing.)
>
> But we’re using “indent-sexp”, which only indents the expression that
> belongs to the matched package name.

Right, Ludo you missunderstood: only the specified package will be
indented.

>> What about committing it as a script, say
>> etc/devel/indent-scheme-code.sh, and mention it under “Submitting
>> Patches” and “Formatting Code”?
>
> Sounds good to me.  Alex, would you like to do it?

Sorry, I wouldn't :-)

-- 
Alex

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

* Re: indent with emacs batch mode
  2017-01-08 13:32     ` Alex Kost
@ 2017-01-12 14:01       ` Ludovic Courtès
  2017-05-28 16:54         ` Andreas Enge
  0 siblings, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2017-01-12 14:01 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> Ricardo Wurmus (2017-01-07 08:25 +0100) wrote:
>
>> Alex Kost wrote:
>>
>>> All that stuff can work without 'emacs-guix' (if the line with
>>> 'guix-devel-mode' scheme hook will be removed), but in this case the
>>> package may not be indented properly.
>>
>> Guix still comes with a “.dir-locals.el” that specifies the indentation
>> rules, doesn’t it?  Can we use that?
>
> Oof, it took me some time to figure it out :-)
>
> So here is the version that requires only emacs and ".dir-locals.el"
> file from the git repo:
>
> ;; Load Scheme indentation rules from "~/src/guix/.dir-locals.el".
> (with-temp-buffer
>   (scheme-mode)
>   (let ((default-directory (file-name-as-directory "~/src/guix"))
>         (enable-local-variables :all))
>     (hack-dir-local-variables)
>     (hack-local-variables-apply)))
>
> (pcase command-line-args-left
>   (`(,file-name ,package-name)
>    (find-file file-name)
>    (goto-char (point-min))
>    (if (re-search-forward (concat "^(define\\(-public\\) +"
>                                   package-name)
>                           nil t)
>        (progn
>          (beginning-of-defun)
>          (indent-sexp)
>          (save-buffer)
>          (message "Done!"))
>      (error "Package '%s' not found in '%s'"
>             package-name file-name))))
>
>
> Emacs can be run like this:
>
>   emacs -Q --batch -l indent-package-expr.el package-file.scm package-name

I’ve pushed it as 7bb2b10cd01a076d7d5e964ed433e62846042859 along with
some doc.

Thanks!

Ludo’.

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

* Re: indent with emacs batch mode
  2017-01-12 14:01       ` Ludovic Courtès
@ 2017-05-28 16:54         ` Andreas Enge
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Enge @ 2017-05-28 16:54 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, Alex Kost

Hello,

On Thu, Jan 12, 2017 at 03:01:38PM +0100, Ludovic Courtès wrote:
> I’ve pushed it as 7bb2b10cd01a076d7d5e964ed433e62846042859 along with
> some doc.

thanks to Ricardo, Alex and you for this extremely useful script!
I just installed emacs-no-x into my profile ;-)
And the script worked like a charm on a new package.

Andreas

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

end of thread, other threads:[~2017-05-28 16:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-06 15:29 indent with emacs batch mode Ricardo Wurmus
2017-01-07  5:59 ` Alex Kost
2017-01-07  7:25   ` Ricardo Wurmus
2017-01-08 13:32     ` Alex Kost
2017-01-12 14:01       ` Ludovic Courtès
2017-05-28 16:54         ` Andreas Enge
2017-01-07 21:17   ` Ludovic Courtès
2017-01-07 21:21     ` Ricardo Wurmus
2017-01-08 13:48       ` 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.