unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...)
@ 2014-02-15 21:41 Alan Mackenzie
  2014-02-15 22:20 ` Andreas Schwab
  2014-02-16  2:51 ` Glenn Morris
  0 siblings, 2 replies; 4+ messages in thread
From: Alan Mackenzie @ 2014-02-15 21:41 UTC (permalink / raw)
  To: 16766

With a newly updated trunk, I put the following into *scratch* and
evaluated it with C-u C-x C-e:

(pp (macroexpand-all '(define-minor-mode electric-indent-local-mode
  "Toggle `electric-indent-mode' only in this buffer."
  :variable (buffer-local-value 'electric-indent-mode (current-buffer))
  (cond
   ((eq electric-indent-mode (default-value 'electric-indent-mode))
    (kill-local-variable 'electric-indent-mode))
   ((not (default-value 'electric-indent-mode))
    ;; Locally enabled, but globally disabled.
    (electric-indent-mode 1)                ; Setup the hooks.
    (setq-default electric-indent-mode nil) ; But keep it globally disabled.
    )))))

(This is the definition of electric-indent-local-mode from electric.el).
The expansion of this code used the variable `v' twice inside a `let*'
form.  At a guess, the unusual :variable form is responsible.

It also seems stupid that the code is messing around with
`(current-buffer)' and `(set-buffer)' at all.  What's this all about?

Here is the expansion:

(progn nil
       (defalias 'electric-indent-local-mode
         #'(lambda
             (&optional arg)
             "Toggle `electric-indent-mode' only in this buffer."
             (interactive
              (list
               (or current-prefix-arg 'toggle)))
             (let
                 ((last-message
                   (current-message)))
               (let*
                   ((v                        <==================================
                     (current-buffer))
                    (v                        <==================================
                     (if
                         (eq arg 'toggle)
                         (not
                          (buffer-local-value 'electric-indent-mode
                                              (current-buffer)))
                       (>
                        (prefix-numeric-value arg)
                        0))))
                 (save-current-buffer
                   (set-buffer v)             <==================================
                   (set
                    (make-local-variable 'electric-indent-mode)
                    v)))                      <===================================
               (cond
                ((eq electric-indent-mode
                     (default-value 'electric-indent-mode))
                 (kill-local-variable 'electric-indent-mode))
                ((not
                  (default-value 'electric-indent-mode))
                 (electric-indent-mode 1)
                 (setq-default electric-indent-mode nil)))
               (run-hooks 'electric-indent-local-mode-hook
                          (if
                              (buffer-local-value 'electric-indent-mode
                                                  (current-buffer))
                              'electric-indent-local-mode-on-hook 'electric-indent-local-mode-off-hook))
               (if
                   (called-interactively-p 'any)
                   (progn nil
                          (if
                              (and
                               (current-message)
                               (not
                                (equal last-message
                                       (current-message))))
                              nil
                            (message "Electric-Indent-Local mode %sabled"
                                     (if
                                         (buffer-local-value 'electric-indent-mode
                                                             (current-buffer))
                                         "en" "dis"))))))
             (force-mode-line-update)
             (buffer-local-value 'electric-indent-mode
                                 (current-buffer))))
       :autoload-end
       (defvar electric-indent-local-mode-hook nil "Hook run after entering or leaving `(buffer-local-value (quote electric-indent-mode) (current-buffer))'.\nNo problems result if this variable is not bound.\n`add-hook' automatically binds\ it.  (This is true for all hook variables.)")
       nil nil)



-- 
Alan Mackenzie (Nuremberg, Germany).





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

end of thread, other threads:[~2014-02-16  2:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-15 21:41 bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...) Alan Mackenzie
2014-02-15 22:20 ` Andreas Schwab
2014-02-15 22:50   ` Alan Mackenzie
2014-02-16  2:51 ` Glenn Morris

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

	https://git.savannah.gnu.org/cgit/emacs.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).