all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 16766@debbugs.gnu.org
Subject: bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...)
Date: Sat, 15 Feb 2014 21:41:09 +0000	[thread overview]
Message-ID: <20140215214109.GA24019@acm.acm> (raw)

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	other threads:[~2014-02-15 21:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-15 21:41 Alan Mackenzie [this message]
2014-02-15 22:20 ` bug#16766: Bad macro expansion of (define-minor-mode electric-indent-local-mode ...) Andreas Schwab
2014-02-15 22:50   ` Alan Mackenzie
2014-02-16  2:51 ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140215214109.GA24019@acm.acm \
    --to=acm@muc.de \
    --cc=16766@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.