bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16766: Bad macro expansion of (define-minor-mode electric-indent-loc


From: Alan Mackenzie
Subject: bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...)
Date: Sat, 15 Feb 2014 21:41:09 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

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).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]