all messages for Emacs-related lists mirrored at yhetil.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

* bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...)
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2014-02-15 22:20 UTC (permalink / raw
  To: Alan Mackenzie; +Cc: 16766

Alan Mackenzie <acm@muc.de> writes:

> The expansion of this code used the variable `v' twice inside a `let*'
> form.

They are different symbols.  Try setting print-gensym and print-circle.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...)
  2014-02-15 22:20 ` Andreas Schwab
@ 2014-02-15 22:50   ` Alan Mackenzie
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2014-02-15 22:50 UTC (permalink / raw
  To: Andreas Schwab; +Cc: 16766

Hi, Andreas.

On Sat, Feb 15, 2014 at 11:20:38PM +0100, Andreas Schwab wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > The expansion of this code used the variable `v' twice inside a `let*'
> > form.

> They are different symbols.  Try setting print-gensym and print-circle.

OK, different uninterned symbols with the same print-name.  YUCK!

Thanks for the elucidation.

> Andreas.

> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."

-- 
Alan Mackenzie (Nuremberg, Germany).





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

* bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...)
  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-16  2:51 ` Glenn Morris
  1 sibling, 0 replies; 4+ messages in thread
From: Glenn Morris @ 2014-02-16  2:51 UTC (permalink / raw
  To: Alan Mackenzie; +Cc: 16766

Alan Mackenzie wrote:

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

That's the setf function for buffer-local-value.





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