[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Typo in 'org-without-partial-completion'
From: |
David Maus |
Subject: |
Re: [O] Typo in 'org-without-partial-completion' |
Date: |
Sat, 02 Jul 2011 09:34:37 +0200 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/23.2 (i486-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
At Thu, 30 Jun 2011 21:28:08 +0200,
David Maus wrote:
>
> At Thu, 30 Jun 2011 11:12:15 +0200,
> Bastien wrote:
> >
> > Hi Paul,
> >
> > Paul Sexton <address@hidden> writes:
> >
> > > I think there's an error in 'org-without-partial-completion' in
> > > org-macs.el.
> > > The variable pc-mode gets bound to the value of partial-completion-mode -
> > > but
> > > this is a VARIABLE (t if that mode is enabled). Funcalling the value of
> > > the variable produces an error, unsurprisingly. This breaks insertion of
> > > properties with 'org-set-property'.
> > >
> > > Fixing it involves quoting the the symbol as shown below:
> > >
> > >
> > > (defmacro org-without-partial-completion (&rest body)
> > > `(let ((pc-mode (and (boundp 'partial-completion-mode)
> > > 'partial-completion-mode))) ; <-- quote added
> > > (unwind-protect
> > > (progn
> > > (when pc-mode (funcall pc-mode -1))
> > > ,@body)
> > > (when pc-mode (funcall pc-mode 1)))))
> >
> > I've just reverted this modification, per Sebastian report.
> >
> > Can you be more precise about the problem it creates with
> > org-set-property?
> >
> > Can you check if this version fixes the problems, if any?
> >
> > #+begin_src emacs-lisp
> > (defmacro org-without-partial-completion (&rest body)
> > `(let ((pc-mode ,(and (boundp 'partial-completion-mode)
> > 'partial-completion-mode)))
> > (unwind-protect
> > (progn
> > (when pc-mode (funcall pc-mode -1))
> > ,@body)
> > (when pc-mode (funcall pc-mode 1)))))
> > #+end_src emacs-lisp
>
> No, I think this won't work. On compile time the byte compiler will
> expand the macro and place the expansion in the byte compiled
> lisp. Thus it will evaluate the ,(and ...) condition at compile time.
>
> http://www.gnu.org/software/emacs/elisp/html_node/Compiling-Macros.html#Compiling-Macros
>
> #+begin_quote
> When a macro call appears in a Lisp program being compiled, the Lisp
> compiler calls the macro definition just as the interpreter would, and
> receives an expansion. But instead of evaluating this expansion, it
> compiles the expansion as if it had appeared directly in the
> program. As a result, the compiled code produces the value and side
> effects intended for the macro, but executes at full compiled
> speed. This would not work if the macro body computed the value and
> side effects itself—they would be computed at compile time, which is
> not useful.
> #+end_quote
>
> What about this:
>
> #+begin_src emacs-lisp
> (defmacro org-without-partial-completion (&rest body)
> `(let ((pc-mode-p (and (boundp 'partial-completion-mode)
> (fboundp 'partial-completion-mode))))
> (when pc-mode-p
> (unwind-protect
> (progn
> (partial-completion-mode -1)
> ,@body)
> (partial-completion-mode 1)))))
> #+end_src
>
> This will turn off partial-completion-mode if the symbol is non-nil
> and callable.
Or even better:
#+begin_src emacs-lisp
(defmacro org-without-partial-completion (&rest body)
`(when (and (boundp 'partial-completion-mode)
(fboundp 'partial-completion-mode))
(unwind-protect
(progn
(partial-completion-mode -1)
,@body)
(partial-completion-mode 1))))
#+end_src
This avoids leaking if 'body happens to uses a symbol 'pc-mode-p in a
different context.
Best,
-- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... address@hidden
Email..... address@hidden
pgpUgP2N5aemi.pgp
Description: PGP signature
- Re: [O] Typo in 'org-without-partial-completion',
David Maus <=