* bug#24848: 24.5; "Local rules set"
@ 2016-11-01 15:07 richard.wiseman
2017-08-24 11:39 ` bug#24848: Any progress? richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2016-11-01 15:07 UTC (permalink / raw
To: 24848
[-- Attachment #1: Type: text/plain, Size: 5232 bytes --]
--text follows this line--
I tried to send this earlier but I think it failed. I got no confirmation of it sending anyway, so here's essentially the same thing again...
I've been using sh-mode to edit bash scripts, but I noticed that the indent after a "then" was twice what it should be (and twice what it is after an "else"). I googled and discovered that I can run "sh-learn-buffer-indent" to learn the indentation that I want; this prompted me of a shortcut "C-c >" which I've then been using.
It works perfectly!
But it only applies to the current session and all the "C-c >" command says when complete is "Local rules set". It doesn't say what those rules are or how to make them permanent. It doesn't even say what it means by "rules" actually. I put a question on StackOverflow and was recommended to submit a bug report, hence this email.
So could the "Local rules set" message be changed to include instructions on how to make the changes permanent please?
Thanks,
Richard
In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
of 2016-04-17 on lgw01-04, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11803000
System Description: Linux Mint 18 Sarah
Configured using:
`configure --build x86_64-linux-gnu --prefix=/usr
--sharedstatedir=/var/lib --libexecdir=/usr/lib
--localstatedir=/var/lib --infodir=/usr/share/info
--mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
--libexecdir=/usr/lib --localstatedir=/var/lib
--infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
--with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
'CFLAGS=-g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
-D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''
Important settings:
value of $LANG: en_GB.UTF-8
locale-coding-system: utf-8-unix
Major mode: Shell-script
Minor modes in effect:
sh-electric-here-document-mode: t
delete-selection-mode: t
show-paren-mode: t
tooltip-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Recent messages:
C-x M-i is undefined
byte-code: End of buffer [4 times]
byte-code: Beginning of buffer [16 times]
Load-path shadows:
/usr/share/emacs/24.5/site-lisp/sgml-mode hides /usr/share/emacs/site-lisp/sgml-mode
/usr/share/emacs/24.5/site-lisp/php-mode hides /usr/share/emacs/site-lisp/php-mode
/usr/share/emacs/24.5/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup
/usr/share/emacs24/site-lisp/cmake-data/cmake-mode hides /usr/share/emacs/site-lisp/cmake-mode
/usr/share/emacs/24.5/site-lisp/sgml-mode hides /usr/share/emacs/24.5/lisp/textmodes/sgml-mode
/usr/share/emacs/24.5/site-lisp/sh-script hides /usr/share/emacs/24.5/lisp/progmodes/sh-script
Features:
(mailalias mailclient browse-url shadow sort gnus-util mail-extr
emacsbug message format-spec rfc822 mml mml-sec mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils pp apropos
cus-theme eieio-custom eieio byte-opt bytecomp byte-compile cl-extra
cconv eieio-core wid-browse tree-widget cus-edit wid-edit help-mode
easymenu tabify sh-script smie executable web-mode advice help-fns
disp-table edmacro kmacro cl-loaddefs cl-lib sgml-mode delsel paren
cus-start cus-load time-date tooltip electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
gfilenotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty emacs)
Memory information:
((conses 16 138222 26012)
(symbols 48 23067 0)
(miscs 40 111 525)
(strings 32 27088 5121)
(string-bytes 1 727532)
(vectors 16 15338)
(vector-slots 8 465085 10423)
(floats 8 90 790)
(intervals 56 1256 253)
(buffers 960 17)
(heap 1024 34477 1884))
[-- Attachment #2: Type: text/html, Size: 7381 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: Any progress?
2016-11-01 15:07 bug#24848: 24.5; "Local rules set" richard.wiseman
@ 2017-08-24 11:39 ` richard.wiseman
2017-08-24 12:41 ` bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent? npostavs
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-08-24 11:39 UTC (permalink / raw
To: 24848
[-- Attachment #1: Type: text/plain, Size: 554 bytes --]
Hi,
I've looked at the bug online and all I can see is my own report, which was submitted 295 days ago.
Once I've done sh-learn-buffer-indent, all I really need to know is how to save the "local rules". Perhaps it isn't a bug ... but if it isn't, how come when I do M-x customize-unsaved it responds "No user options are set but unsaved"? Perhaps it is not stored as an option, I don't know, but this is why I submitted the bug: nobody seems to know where this "local config" is saved or how to make it permanent!
Regards,
Richard
[-- Attachment #2: Type: text/html, Size: 1204 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-24 11:39 ` bug#24848: Any progress? richard.wiseman
@ 2017-08-24 12:41 ` npostavs
2017-08-24 13:44 ` richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: npostavs @ 2017-08-24 12:41 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
retitle 24848 [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
quit
<richard.wiseman@bt.com> writes:
> I've looked at the bug online and all I can see is my own report,
> which was submitted 295 days ago.
Hi, sorry nobody responded earlier. Actually I would generally
recommend that you send a followup message after a week or two if there
hasn't been any response. By that time it's probably fallen off the
radar from "current" bugs and become one of thousands of "open" bugs.
(Also, your title could be a bit more descriptive, it's so vague that I
would probably skip over it without noticing if I saw it in a list.)
> Once I've done sh-learn-buffer-indent, all I really need to know is
> how to save the "local rules". Perhaps it isn't a bug ... but if it
> isn't, how come when I do M-x customize-unsaved it responds "No user
> options are set but unsaved"? Perhaps it is not stored as an option,
> I don't know, but this is why I submitted the bug: nobody seems to
> know where this "local config" is saved or how to make it permanent!
Does this commentary from sh-script.el help? (not that info hidden away
in comments is a substitute for actual docs; I'm just trying to make
sure we understand the problem.)
;; Saving indentation values
;; -------------------------
;; After you've learned the values in a buffer, how to you remember
;; them? Originally I had hoped that `sh-learn-buffer-indent'
;; would make this unnecessary; simply learn the values when you visit
;; the buffer.
;; You can do this automatically like this:
;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent)
;;
;; However... `sh-learn-buffer-indent' is extremely slow,
;; especially on large-ish buffer. Also, if there are conflicts the
;; "last one wins" which may not produce the desired setting.
;;
;; So...There is a minimal way of being able to save indentation values and
;; to reload them in another buffer or at another point in time.
;;
;; Use `sh-name-style' to give a name to the indentation settings of
;; the current buffer.
;; Use `sh-load-style' to load indentation settings for the current
;; buffer from a specific style.
;; Use `sh-save-styles-to-buffer' to write all the styles to a buffer
;; in lisp code. You can then store it in a file and later use
;; `load-file' to load it.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-24 12:41 ` bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent? npostavs
@ 2017-08-24 13:44 ` richard.wiseman
2017-08-25 1:12 ` npostavs
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-08-24 13:44 UTC (permalink / raw
To: 24848
Hi Noam,
Thanks for such a quick response!
I've had a try with the commands in the comment. Here's what I did:
1. Load a correctly-formatted bash script.
2. Move to a line that I know will be problematic -- it always wants to indent 4 characters after a "then" -- and press tab. Sure enough, the indentation changes to how I don't like.
3. Undo that to restore the correctly-formatted bash script.
4. Run sh-learn-buffer-indent.
5. Press tab on that problematic line; this time, correctly, the indentation doesn't change.
6. Run sh-name-style and call it "bash".
7. Run sh-save-styles-to-buffer and let it use *scratch*.
8. Copy the output in *scratch* into my .emacs file.
9. Quit emacs.
10. Start emacs.
11. Load the same bash script.
12. Load the style, "bash".
13. Press tab on that problematic line. It still indents incorrectly, so although sh-save-styles-to-buffer saved styles (see below), it evidently didn't include the modification. :-(
Sadly, even the following doesn't work:
1. Load a correctly-formatted bash script.
2. Move to a line that I know will be problematic -- it always wants to indent 4 characters after a "then" -- and press tab. Sure enough, the indentation changes to how I don't like.
3. Undo that to restore the correctly-formatted bash script.
4. Run sh-learn-buffer-indent.
5. Press tab on that problematic line; this time, correctly, the indentation doesn't change.
6. Run sh-name-style and call it "bash".
7. Load a different bash script without quitting emacs first.
8. Run sh-load-style and press tab so it auto-completes to "bash".
9. Press tab on a problematic line -- indentation is still incorrect.
So the above seem to demonstrate that sh-name-buffer and sh-save-styles-to-buffer don't save all indentation information.
Here's what sh-save-styles-to-buffer puts in my *scratch* buffer:
(setq sh-styles-alist
'(("bash"
(sh-basic-offset . 2)
(sh-first-lines-indent . 0)
(sh-indent-after-case . +)
(sh-indent-after-do . +)
(sh-indent-after-done . 0)
(sh-indent-after-else . +)
(sh-indent-after-if . +)
(sh-indent-after-loop-construct . +)
(sh-indent-after-open . +)
(sh-indent-comment . t)
(sh-indent-for-case-alt . ++)
(sh-indent-for-case-label . +)
(sh-indent-for-continuation . +)
(sh-indent-for-do . 0)
(sh-indent-for-done . 0)
(sh-indent-for-else . 0)
(sh-indent-for-fi . 0)
(sh-indent-for-then . 0))))
Please let me know if you'd like any further information.
Thanks again for the message,
Richard
PS - I guess (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent) will help me if my file is already properly formatted, but I would like to know how to save ALL the indent rules established by sh-learn-buffer-indent if at all possible!
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-24 13:44 ` richard.wiseman
@ 2017-08-25 1:12 ` npostavs
2017-08-25 8:11 ` richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: npostavs @ 2017-08-25 1:12 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
<richard.wiseman@bt.com> writes:
> So the above seem to demonstrate that sh-name-buffer and
> sh-save-styles-to-buffer don't save all indentation information.
Oh, I think the commentary I found is actually for the old sh-script
specific indentation. If 'sh-use-smie' is set (the default) you should
rather use M-x smie-save-config. And then it seems an extra step is
needed to activate it in the current session, evalute this expression:
(customize-set-variable 'smie-config
;; This value is set by `smie-save-config'.
'((sh-mode (-2 :before "then" 0))))
I'm not sure if this is because I'm testing with 'emacs -Q', or
something is missing from 'smie-save-config'. I think normally the
value would saved with the other customized options and work without any
extra effort.
> Please let me know if you'd like any further information.
Could you also please post a script which gives the bad indentation?
This could be another bug in itself.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 1:12 ` npostavs
@ 2017-08-25 8:11 ` richard.wiseman
2017-08-25 8:37 ` richard.wiseman
2017-08-25 12:07 ` npostavs
0 siblings, 2 replies; 24+ messages in thread
From: richard.wiseman @ 2017-08-25 8:11 UTC (permalink / raw
To: npostavs, 24848
Hi Noam,
Thanks for the suggestions.
I don't know whether my Emacs uses smie for sh-mode but there's apparently no sh-use-smie variable set by default.
However, running smie-config-guess seems to have the same effect as sm-learn-buffer-indent so perhaps it does. Unfortunately, I've still not managed to save the config.
Here's what I did:
1. I ran smie-config-guess on a correctly-indented bash script (see below) and confirmed that it now indents as I would expect when I hit tab on any line).
2. I then ran smie-save-config and it said it saved it to smie-config.
3. I ran customize-variable on smie-config and its value is now ((2 :elem basic 4)) which doesn't make any mention of indenting after "then" which is weird, because as I said, it does now indent correctly in this buffer.
4. I then clicked Apply and Save to add the setting to my ~/.emacs file.
5. I confirmed that it now appears in the (custom-set-variables ... ) section.
6. I restarted Emacs and loaded the bash script.
7. As feared, indentation is back to the way I don't like.
8. I then modified the smie-config entry in (custom-set-variables ... ) to correspond with your expression (that mentions "then").
9. I restarted Emacs and loaded the bash script.
10. Sadly, indentation is still unaffected.
The bash script I've used as a test here is:
#!/usr/bin/env bash
if [ "$1" ]
then
echo "First argument is: $1"
else
echo "No arguments"
fi
In case there's a problem with formatting by the time this email reaches you, only the two echo lines are indented, and each by two spaces. Hitting tab on the first of these changes the indent to four spaces; on the second, indentation remains at two.
Regards,
Richard
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 8:11 ` richard.wiseman
@ 2017-08-25 8:37 ` richard.wiseman
2017-08-25 12:07 ` npostavs
1 sibling, 0 replies; 24+ messages in thread
From: richard.wiseman @ 2017-08-25 8:37 UTC (permalink / raw
To: npostavs, 24848
PS When I first load the bash script, if I run smie-config-show-indent on the line after "then", I get:
Rules used: :elem basic -> 4, :after "then" -> nil
If I then run smie-config-guess followed by smie-config-show-indent on the same line, I now get:
Rules used: :elem basic -> 2(via 4), :after "then" -> nil
If I run smie-config-save (response: "Mode rules replaced in `smie-config'") followed by customize-variable smie-config the value is simply:
((2 :elem basic 4))
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 8:11 ` richard.wiseman
2017-08-25 8:37 ` richard.wiseman
@ 2017-08-25 12:07 ` npostavs
2017-08-25 13:44 ` richard.wiseman
1 sibling, 1 reply; 24+ messages in thread
From: npostavs @ 2017-08-25 12:07 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
<richard.wiseman@bt.com> writes:
> I don't know whether my Emacs uses smie for sh-mode but there's
> apparently no sh-use-smie variable set by default.
What Emacs version do you have? (Based on what you said below, it
sounds like smie is being used.)
> The bash script I've used as a test here is:
>
> #!/usr/bin/env bash
>
> if [ "$1" ]
> then
> echo "First argument is: $1"
> else
> echo "No arguments"
> fi
Ah, so you've set sh-basic-offset to 2, right? That's Bug#21751. Hmm,
it looks like the smie code is following sh-indentation instead of
sh-basic-offset. It's not clear to me why both of those variables
exist...
> 3. I ran customize-variable on smie-config and its value is now ((2
> :elem basic 4)) which doesn't make any mention of indenting after
> "then" which is weird, because as I said, it does now indent correctly
> in this buffer.
When I set sh-basic-offset to 2, I get that value for smie-config as
well.
> 7. As feared, indentation is back to the way I don't like.
>
> However, running smie-config-guess seems to have the same effect as
> sm-learn-buffer-indent so perhaps it does. Unfortunately, I've still
> not managed to save the config.
I followed your steps and got similar results. The problem is actually
that the config doesn't get loaded properly. It works if I then do
8. M-x customize-option RET smie-config RET
9. Modify the text of the value field, e.g., by adding a space at the
end, so that the "State" turns to EDITED.
10. Click the "Apply" button (this is equivalent to the
(customize-set-variable 'smie-config ...) expression I mentioned
before).
11. Go to the bash script buffer and run M-x normal-mode RET so that the
mode hooks are run again.
12. Indentation is correct.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 12:07 ` npostavs
@ 2017-08-25 13:44 ` richard.wiseman
2017-08-25 14:31 ` richard.wiseman
2017-08-30 23:49 ` npostavs
0 siblings, 2 replies; 24+ messages in thread
From: richard.wiseman @ 2017-08-25 13:44 UTC (permalink / raw
To: npostavs, 24848
I'm using Emacs v24.5.1 and yes, I've a basic offset of 2 set...
(custom-set-variables
;; lots of stuff
'(sh-basic-offset 2)
;; lots of stuff
)
I was interested that you mentioned sh-indentation as an alternative to sh-basic-offset so I added that too, and that resulted in the indentation that I want!
So that solves the problem that I was trying to solve by saving learned indentation. :-)
Anyway, to help get to the bottom of this, I disabled sh-indentation and tried your steps around editing smie-config and M-x normal-mode and I got the same result as you: it worked.
So as you indicated, it appears to be that smie-config isn't being loaded (properly) when Emacs starts.
I await your next inspiration! :-)
Thanks,
Richard
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 13:44 ` richard.wiseman
@ 2017-08-25 14:31 ` richard.wiseman
2017-08-26 20:08 ` Noam Postavsky
2017-08-30 23:49 ` npostavs
1 sibling, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-08-25 14:31 UTC (permalink / raw
To: npostavs, 24848
A little extra information that will possibly muddy the waters...
I've the same version of Emacs on a Windows machine (I use Linux Mint normally) and I've essentially the same ~/.emacs file on both machines, but for some reason the Windows one behaves differently for bash scripts! Perhaps the sh-mode comes from somewhere else or is a different version, I don't know. On Windows, though, when I go to a correctly indented line in a function and press tab, it indents incorrectly! :-(
So for example,
#!/usr/bin/env bash
function f {
echo Hello from the function
}
f
On Windows, when I'm on the "echo" line and press tab, it indents to 4 spaces; on Linux it doesn't.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 14:31 ` richard.wiseman
@ 2017-08-26 20:08 ` Noam Postavsky
2017-08-29 7:43 ` richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: Noam Postavsky @ 2017-08-26 20:08 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
On Fri, Aug 25, 2017 at 10:31 AM, <richard.wiseman@bt.com> wrote:
> A little extra information that will possibly muddy the waters...
>
> I've the same version of Emacs on a Windows machine (I use Linux Mint normally) and I've essentially the same ~/.emacs file on both machines, but for some reason the Windows one behaves differently for bash scripts! Perhaps the sh-mode comes from somewhere else or is a different version, I don't know. On Windows, though, when I go to a correctly indented line in a function and press tab, it indents incorrectly! :-(
>
> So for example,
>
> #!/usr/bin/env bash
>
> function f {
> echo Hello from the function
> }
>
> f
>
> On Windows, when I'm on the "echo" line and press tab, it indents to 4 spaces; on Linux it doesn't.
Can you narrow down the relevant .emacs settings? If I do emacs -Q
--eval "(setq sh-basic-offset 2)" hello-function.sh on Windows Emacs
24.5, I get 2 space indentation.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-25 13:44 ` richard.wiseman
2017-08-25 14:31 ` richard.wiseman
@ 2017-08-30 23:49 ` npostavs
2017-09-04 8:30 ` richard.wiseman
1 sibling, 1 reply; 24+ messages in thread
From: npostavs @ 2017-08-30 23:49 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
[-- Attachment #1: Type: text/plain, Size: 657 bytes --]
tags 24848 + patch
quit
<richard.wiseman@bt.com> writes:
> Anyway, to help get to the bottom of this, I disabled sh-indentation
> and tried your steps around editing smie-config and M-x normal-mode
> and I got the same result as you: it worked.
>
> So as you indicated, it appears to be that smie-config isn't being loaded (properly) when Emacs starts.
>
> I await your next inspiration! :-)
Okay, the patch below fixes the loading for me. I also added a mention
of `smie-config-guess' in `sh-learn-buffer-indent's docstring so that it
should be possible to figure how to save config rules by reading
docstrings rather than hunting in the source code.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3024 bytes --]
From 69365325783e5f980cd0e1460465b8562a5180ef Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 30 Aug 2017 19:31:48 -0400
Subject: [PATCH v1] Fix loading of smie-config rules (Bug#24848)
* lisp/emacs-lisp/smie.el (smie-config--setter): Use `set-default'
instead of `setq-default'.
(smie-config): Use `custom-initialize-set' instead of
`custom-initialize-default' as the :initialize argument.
* lisp/progmodes/sh-script.el (sh-learn-buffer-indent): Mention that
we call `smie-config-guess' so that the user will have a chance to
find the correct docstring to consult. Remove hedging comments
regarding use of abnormal hooks.
---
lisp/emacs-lisp/smie.el | 4 ++--
lisp/progmodes/sh-script.el | 8 +++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index 7baccbc752..9afbfe4446 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -1956,7 +1956,7 @@ smie-config--mode-hook
(defvar smie-config--modefuns nil)
(defun smie-config--setter (var value)
- (setq-default var value)
+ (set-default var value)
(let ((old-modefuns smie-config--modefuns))
(setq smie-config--modefuns nil)
(pcase-dolist (`(,mode . ,rules) value)
@@ -1982,7 +1982,7 @@ smie-config
;; FIXME improve value-type.
:type '(choice (const nil)
(alist :key-type symbol))
- :initialize 'custom-initialize-default
+ :initialize 'custom-initialize-set
:set #'smie-config--setter)
(defun smie-config-local (rules)
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 07604ad665..ca31635dbc 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -3600,6 +3600,10 @@ sh-learned-buffer-hook
(defun sh-learn-buffer-indent (&optional arg)
"Learn how to indent the buffer the way it currently is.
+If `sh-use-smie' is non-nil, call `smie-config-guess'.
+Otherwise, run the sh-script specific indent learning command, as
+decribed below.
+
Output in buffer \"*indent*\" shows any lines which have conflicting
values of a variable, and the final value of all variables learned.
When called interactively, pop to this buffer automatically if
@@ -3616,8 +3620,7 @@ sh-learn-buffer-indent
Abnormal hook `sh-learned-buffer-hook' if non-nil is called when the
function completes. The function is abnormal because it is called
-with an alist of variables learned. This feature may be changed or
-removed in the future.
+with an alist of variables learned.
This command can often take a long time to run."
(interactive "P")
@@ -3815,7 +3818,6 @@ sh-learn-buffer-indent
" has" "s have")
(if (zerop num-diffs)
"." ":"))))))
- ;; Are abnormal hooks considered bad form?
(run-hook-with-args 'sh-learned-buffer-hook learned-var-list)
(and (called-interactively-p 'any)
(or sh-popup-occur-buffer (> num-diffs 0))
--
2.14.1
^ permalink raw reply related [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-08-30 23:49 ` npostavs
@ 2017-09-04 8:30 ` richard.wiseman
2017-09-08 23:15 ` npostavs
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-09-04 8:30 UTC (permalink / raw
To: npostavs, 24848
Thanks Noam. I'm not sure I've got any way to test this patch, though... I don't seem to have an smie.el file anywhere. I've installed the emacs24-el package expecting that to contain it but it doesn't -- at least, I've searched my entire hard drive for it (using sudo, just in case) and it wasn't found.
________________________________________
From: Noam Postavsky <npostavs@gmail.com> on behalf of npostavs@users.sourceforge.net <npostavs@users.sourceforge.net>
Sent: 31 August 2017 00:49
To: Wiseman,R,Richard,TUK2 R
Cc: 24848@debbugs.gnu.org
Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
tags 24848 + patch
quit
<richard.wiseman@bt.com> writes:
> Anyway, to help get to the bottom of this, I disabled sh-indentation
> and tried your steps around editing smie-config and M-x normal-mode
> and I got the same result as you: it worked.
>
> So as you indicated, it appears to be that smie-config isn't being loaded (properly) when Emacs starts.
>
> I await your next inspiration! :-)
Okay, the patch below fixes the loading for me. I also added a mention
of `smie-config-guess' in `sh-learn-buffer-indent's docstring so that it
should be possible to figure how to save config rules by reading
docstrings rather than hunting in the source code.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-04 8:30 ` richard.wiseman
@ 2017-09-08 23:15 ` npostavs
2017-09-11 7:44 ` richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: npostavs @ 2017-09-08 23:15 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
<richard.wiseman@bt.com> writes:
> Thanks Noam. I'm not sure I've got any way to test this patch,
> though... I don't seem to have an smie.el file anywhere. I've
> installed the emacs24-el package expecting that to contain it but it
> doesn't -- at least, I've searched my entire hard drive for it (using
> sudo, just in case) and it wasn't found.
What does M-x find-library RET smie RET give you?
I see /usr/share/emacs/24.5/lisp/emacs-lisp/smie.el.gz listed in
https://packages.ubuntu.com/zesty/all/emacs24-el/filelist. If you have
the gzipped version, you might have to unzip before you can apply the
patch.
Alternatively, I'm fairly sure if you just drop the patched definitions
of smie-config--setter and smie-config into your .emacs it will have the
same effect:
(defun smie-config--setter (var value)
(set-default var value)
(let ((old-modefuns smie-config--modefuns))
(setq smie-config--modefuns nil)
(pcase-dolist (`(,mode . ,rules) value)
(let ((modefunname (intern (format "smie-config--modefun-%s" mode))))
(fset modefunname (lambda () (smie-config--mode-hook rules)))
(push modefunname smie-config--modefuns)
(add-hook (intern (format "%s-hook" mode)) modefunname)))
;; Neuter any left-over previously installed hook.
(dolist (modefun old-modefuns)
(unless (memq modefun smie-config--modefuns)
(fset modefun #'ignore)))))
(defcustom smie-config nil
;; FIXME: there should be a file-local equivalent.
"User configuration of SMIE indentation.
This is a list of elements (MODE . RULES), where RULES is a list
of elements describing when and how to change the indentation rules.
Each RULE element should be of the form (NEW KIND TOKEN NORMAL),
where KIND and TOKEN are the elements passed to `smie-rules-function',
NORMAL is the value returned by `smie-rules-function' and NEW is the
value with which to replace it."
:version "24.4"
;; FIXME improve value-type.
:type '(choice (const nil)
(alist :key-type symbol))
:initialize 'custom-initialize-set
:set #'smie-config--setter)
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-08 23:15 ` npostavs
@ 2017-09-11 7:44 ` richard.wiseman
2017-09-11 9:53 ` richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-09-11 7:44 UTC (permalink / raw
To: npostavs, 24848
You're quite right: my smie library is gzipped. I had no idea that might be the case!
I tried your suggestion of putting the code into my .emacs file but it didn't seem to like that...
Warning (initialization): An error occurred while loading `/home/richard/.emacs':
Symbol's value as variable is void: smie-config--modefuns
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
(I put it right at the end: I assumed that was safest.)
I'll try and apply the patch to an unzipped version of smie.el.gz instead, and let you know how that goes.
Regards,
Richard
________________________________________
From: Noam Postavsky <npostavs@gmail.com> on behalf of npostavs@users.sourceforge.net <npostavs@users.sourceforge.net>
Sent: 09 September 2017 00:15
To: Wiseman,R,Richard,TUK2 R
Cc: 24848@debbugs.gnu.org
Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
<richard.wiseman@bt.com> writes:
> Thanks Noam. I'm not sure I've got any way to test this patch,
> though... I don't seem to have an smie.el file anywhere. I've
> installed the emacs24-el package expecting that to contain it but it
> doesn't -- at least, I've searched my entire hard drive for it (using
> sudo, just in case) and it wasn't found.
What does M-x find-library RET smie RET give you?
I see /usr/share/emacs/24.5/lisp/emacs-lisp/smie.el.gz listed in
https://packages.ubuntu.com/zesty/all/emacs24-el/filelist. If you have
the gzipped version, you might have to unzip before you can apply the
patch.
Alternatively, I'm fairly sure if you just drop the patched definitions
of smie-config--setter and smie-config into your .emacs it will have the
same effect:
(defun smie-config--setter (var value)
(set-default var value)
(let ((old-modefuns smie-config--modefuns))
(setq smie-config--modefuns nil)
(pcase-dolist (`(,mode . ,rules) value)
(let ((modefunname (intern (format "smie-config--modefun-%s" mode))))
(fset modefunname (lambda () (smie-config--mode-hook rules)))
(push modefunname smie-config--modefuns)
(add-hook (intern (format "%s-hook" mode)) modefunname)))
;; Neuter any left-over previously installed hook.
(dolist (modefun old-modefuns)
(unless (memq modefun smie-config--modefuns)
(fset modefun #'ignore)))))
(defcustom smie-config nil
;; FIXME: there should be a file-local equivalent.
"User configuration of SMIE indentation.
This is a list of elements (MODE . RULES), where RULES is a list
of elements describing when and how to change the indentation rules.
Each RULE element should be of the form (NEW KIND TOKEN NORMAL),
where KIND and TOKEN are the elements passed to `smie-rules-function',
NORMAL is the value returned by `smie-rules-function' and NEW is the
value with which to replace it."
:version "24.4"
;; FIXME improve value-type.
:type '(choice (const nil)
(alist :key-type symbol))
:initialize 'custom-initialize-set
:set #'smie-config--setter)
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-11 7:44 ` richard.wiseman
@ 2017-09-11 9:53 ` richard.wiseman
2017-09-11 18:48 ` npostavs
2017-09-22 22:46 ` Noam Postavsky
0 siblings, 2 replies; 24+ messages in thread
From: richard.wiseman @ 2017-09-11 9:53 UTC (permalink / raw
To: npostavs, 24848
I've added the code to an unzipped version of smie.el and to sh-script.el and byte-compiled both. Emacs loads without errors now, but to be honest, I'm unsure how to check that it now loads smie-config properly! I load a script file and check the value of smie-config and it says it's set for the current session only but its value is nil.
________________________________________
From: Wiseman,R,Richard,TUK2 R
Sent: 11 September 2017 08:44
To: npostavs@users.sourceforge.net; 24848@debbugs.gnu.org
Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
You're quite right: my smie library is gzipped. I had no idea that might be the case!
I tried your suggestion of putting the code into my .emacs file but it didn't seem to like that...
Warning (initialization): An error occurred while loading `/home/richard/.emacs':
Symbol's value as variable is void: smie-config--modefuns
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
(I put it right at the end: I assumed that was safest.)
I'll try and apply the patch to an unzipped version of smie.el.gz instead, and let you know how that goes.
Regards,
Richard
________________________________________
From: Noam Postavsky <npostavs@gmail.com> on behalf of npostavs@users.sourceforge.net <npostavs@users.sourceforge.net>
Sent: 09 September 2017 00:15
To: Wiseman,R,Richard,TUK2 R
Cc: 24848@debbugs.gnu.org
Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
<richard.wiseman@bt.com> writes:
> Thanks Noam. I'm not sure I've got any way to test this patch,
> though... I don't seem to have an smie.el file anywhere. I've
> installed the emacs24-el package expecting that to contain it but it
> doesn't -- at least, I've searched my entire hard drive for it (using
> sudo, just in case) and it wasn't found.
What does M-x find-library RET smie RET give you?
I see /usr/share/emacs/24.5/lisp/emacs-lisp/smie.el.gz listed in
https://packages.ubuntu.com/zesty/all/emacs24-el/filelist. If you have
the gzipped version, you might have to unzip before you can apply the
patch.
Alternatively, I'm fairly sure if you just drop the patched definitions
of smie-config--setter and smie-config into your .emacs it will have the
same effect:
(defun smie-config--setter (var value)
(set-default var value)
(let ((old-modefuns smie-config--modefuns))
(setq smie-config--modefuns nil)
(pcase-dolist (`(,mode . ,rules) value)
(let ((modefunname (intern (format "smie-config--modefun-%s" mode))))
(fset modefunname (lambda () (smie-config--mode-hook rules)))
(push modefunname smie-config--modefuns)
(add-hook (intern (format "%s-hook" mode)) modefunname)))
;; Neuter any left-over previously installed hook.
(dolist (modefun old-modefuns)
(unless (memq modefun smie-config--modefuns)
(fset modefun #'ignore)))))
(defcustom smie-config nil
;; FIXME: there should be a file-local equivalent.
"User configuration of SMIE indentation.
This is a list of elements (MODE . RULES), where RULES is a list
of elements describing when and how to change the indentation rules.
Each RULE element should be of the form (NEW KIND TOKEN NORMAL),
where KIND and TOKEN are the elements passed to `smie-rules-function',
NORMAL is the value returned by `smie-rules-function' and NEW is the
value with which to replace it."
:version "24.4"
;; FIXME improve value-type.
:type '(choice (const nil)
(alist :key-type symbol))
:initialize 'custom-initialize-set
:set #'smie-config--setter)
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-11 9:53 ` richard.wiseman
@ 2017-09-11 18:48 ` npostavs
2017-09-12 7:09 ` richard.wiseman
2017-09-22 22:46 ` Noam Postavsky
1 sibling, 1 reply; 24+ messages in thread
From: npostavs @ 2017-09-11 18:48 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
<richard.wiseman@bt.com> writes:
> I've added the code to an unzipped version of smie.el and to
> sh-script.el and byte-compiled both.
Actually, sh-script.el isn't strictly needed because it's just a
documentation patch.
> Emacs loads without errors now,
> but to be honest, I'm unsure how to check that it now loads
> smie-config properly! I load a script file and check the value of
> smie-config and it says it's set for the current session only but its
> value is nil.
Do you have something like this in your .emacs?
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(sh-basic-offset 2)
'(smie-config (quote ((sh-mode (-2 :before "then" 0))))))
If not, note that `smie-config-save' doesn't save the rules in a
persistent way, you have to save the `smie-config' variable via the
customize interface for that (this is another thing that should probably
be clarified in the docstring).
> From: Wiseman,R,Richard,TUK2 R
> Sent: 11 September 2017 08:44
> To: npostavs@users.sourceforge.net; 24848@debbugs.gnu.org
> =, 24848@debbugs.gnu.org
> Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
>
> You're quite right: my smie library is gzipped. I had no idea that might be the case!
>
> I tried your suggestion of putting the code into my .emacs file but it didn't seem to like that...
>
>
> Warning (initialization): An error occurred while loading `/home/richard/.emacs':
>
> Symbol's value as variable is void: smie-config--modefuns
Oh right, I forgot about all the dependencies. Well, I guess patching
directly like you've tried above is the most straightforward way.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-11 18:48 ` npostavs
@ 2017-09-12 7:09 ` richard.wiseman
0 siblings, 0 replies; 24+ messages in thread
From: richard.wiseman @ 2017-09-12 7:09 UTC (permalink / raw
To: npostavs, 24848
My ~/.emacs contains, amongst many other things:
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(sh-basic-offset 2)
'(sh-indentation 2)
'(smie-config (quote ((sh-mode (2 :elem basic 4)))))
'(tab-width 2))
Thanks again for the help and for your patience.
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-11 9:53 ` richard.wiseman
2017-09-11 18:48 ` npostavs
@ 2017-09-22 22:46 ` Noam Postavsky
2017-09-25 11:10 ` richard.wiseman
1 sibling, 1 reply; 24+ messages in thread
From: Noam Postavsky @ 2017-09-22 22:46 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
<richard.wiseman@bt.com> writes:
> I've added the code to an unzipped version of smie.el and to
> sh-script.el and byte-compiled both. Emacs loads without errors now,
> but to be honest, I'm unsure how to check that it now loads
> smie-config properly! I load a script file and check the value of
> smie-config and it says it's set for the current session only but its
> value is nil.
Well, the best way to check would to remove the setting of
sh-indentation and make sure you still get the indentation you want.
However, since you're saying smie-config is nil, it seems something went
wrong. Do you have the patched smie.elc on your load-path (i.e., does
M-x locate-library RET smie RET point to the patched version)?
> My ~/.emacs contains, amongst many other things:
>
> (custom-set-variables
> ;; custom-set-variables was added by Custom.
> ;; If you edit it by hand, you could mess it up, so be careful.
> ;; Your init file should contain only one such instance.
> ;; If there is more than one, they won't work right.
> '(sh-basic-offset 2)
> '(sh-indentation 2)
> '(smie-config (quote ((sh-mode (2 :elem basic 4)))))
> '(tab-width 2))
Since you have the smie-config set in your custom variable block, I
can't quite see how it ended up as nil. Is it possible something else
in your config is resetting it?
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-22 22:46 ` Noam Postavsky
@ 2017-09-25 11:10 ` richard.wiseman
2017-09-25 12:19 ` Noam Postavsky
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-09-25 11:10 UTC (permalink / raw
To: npostavs; +Cc: 24848
I've no idea what's going on now!
I've ensured that the patched version is being used. (I had to compile again and copy across, but it's there now.)
But if I use M-x describe-variable RET smie-config RET it complains "[No match]". I can see it in my ~/.emacs file and if I use describe-variable on any of the other things inside custom-set-variables they are all known and have the correct value! I commented out sh-indentation too, just to be safe.
There are no messages when I start Emacs, no errors or anything.
Very confused now!
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-25 11:10 ` richard.wiseman
@ 2017-09-25 12:19 ` Noam Postavsky
2017-09-25 13:06 ` richard.wiseman
0 siblings, 1 reply; 24+ messages in thread
From: Noam Postavsky @ 2017-09-25 12:19 UTC (permalink / raw
To: richard.wiseman; +Cc: 24848
On Mon, Sep 25, 2017 at 7:10 AM, <richard.wiseman@bt.com> wrote:
> I've no idea what's going on now!
>
> I've ensured that the patched version is being used. (I had to compile again and copy across, but it's there now.)
>
> But if I use M-x describe-variable RET smie-config RET it complains "[No match]". I can see it in my ~/.emacs file and if I use describe-variable on any of the other things inside custom-set-variables they are all known and have the correct value! I commented out sh-indentation too, just to be safe.
>
> There are no messages when I start Emacs, no errors or anything.
Oh, I think that is the normal behaviour when you haven't loaded smie
yet. If you then open the bash script file, do things work as
expected?
^ permalink raw reply [flat|nested] 24+ messages in thread
* bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?
2017-09-25 12:19 ` Noam Postavsky
@ 2017-09-25 13:06 ` richard.wiseman
2017-09-25 23:41 ` Noam Postavsky
0 siblings, 1 reply; 24+ messages in thread
From: richard.wiseman @ 2017-09-25 13:06 UTC (permalink / raw
To: npostavs; +Cc: 24848
Thanks Noam. I think I knew that at some point...! Loading a bash script and checking the value of smie-config shows that it has indeed been read in correctly. And my files still indent as expected (and desired!) now that I've removed the sh-indentation from my custom-set-variables section.
Looks like it's all working as it should now! :-)
Thanks again,
Richard
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2017-09-25 23:41 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-01 15:07 bug#24848: 24.5; "Local rules set" richard.wiseman
2017-08-24 11:39 ` bug#24848: Any progress? richard.wiseman
2017-08-24 12:41 ` bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent? npostavs
2017-08-24 13:44 ` richard.wiseman
2017-08-25 1:12 ` npostavs
2017-08-25 8:11 ` richard.wiseman
2017-08-25 8:37 ` richard.wiseman
2017-08-25 12:07 ` npostavs
2017-08-25 13:44 ` richard.wiseman
2017-08-25 14:31 ` richard.wiseman
2017-08-26 20:08 ` Noam Postavsky
2017-08-29 7:43 ` richard.wiseman
2017-08-30 23:49 ` npostavs
2017-09-04 8:30 ` richard.wiseman
2017-09-08 23:15 ` npostavs
2017-09-11 7:44 ` richard.wiseman
2017-09-11 9:53 ` richard.wiseman
2017-09-11 18:48 ` npostavs
2017-09-12 7:09 ` richard.wiseman
2017-09-22 22:46 ` Noam Postavsky
2017-09-25 11:10 ` richard.wiseman
2017-09-25 12:19 ` Noam Postavsky
2017-09-25 13:06 ` richard.wiseman
2017-09-25 23:41 ` Noam Postavsky
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.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.