GNU bug report logs - #24848
[sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?

Previous Next

Package: emacs;

Reported by: <richard.wiseman <at> bt.com>

Date: Tue, 1 Nov 2016 15:37:01 UTC

Severity: minor

Tags: fixed, patch

Merged with 29414

Found in version 24.5

Fixed in version 26.1

Done: Noam Postavsky <npostavs <at> users.sourceforge.net>

Bug is archived. No further changes may be made.

Full log


Message #45 received at control <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: <richard.wiseman <at> bt.com>
Cc: 24848 <at> debbugs.gnu.org
Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from
 sh-learn-buffer-indent?
Date: Wed, 30 Aug 2017 19:49:11 -0400
[Message part 1 (text/plain, inline)]
tags 24848 + patch
quit

<richard.wiseman <at> 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.

[v1-0001-Fix-loading-of-smie-config-rules-Bug-24848.patch (text/x-diff, inline)]
From 69365325783e5f980cd0e1460465b8562a5180ef Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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


This bug report was last modified 7 years and 177 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.