From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Maus Subject: Re: Typo in 'org-without-partial-completion' Date: Sat, 02 Jul 2011 09:34:37 +0200 Message-ID: <87iprl9lv6.wl%dmaus@ictsoc.de> References: <87wrg3k7io.fsf@gnu.org> <871uybdsqf.wl%dmaus@ictsoc.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/signed; boundary="pgp-sign-Multipart_Sat_Jul__2_09:34:37_2011-1"; micalg=pgp-sha256; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:55987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qcuj1-0004Bx-Ee for emacs-orgmode@gnu.org; Sat, 02 Jul 2011 03:34:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qcuiz-0004KB-Sl for emacs-orgmode@gnu.org; Sat, 02 Jul 2011 03:34:47 -0400 Received: from app1a.xlhost.de ([213.202.242.161]:46341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qcuiz-0004K5-Ke for emacs-orgmode@gnu.org; Sat, 02 Jul 2011 03:34:45 -0400 In-Reply-To: <871uybdsqf.wl%dmaus@ictsoc.de> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: David Maus Cc: Bastien , Paul Sexton , emacs-orgmode@gnu.org --pgp-sign-Multipart_Sat_Jul__2_09:34:37_2011-1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable At Thu, 30 Jun 2011 21:28:08 +0200, David Maus wrote: >=20 > At Thu, 30 Jun 2011 11:12:15 +0200, > Bastien wrote: > >=20 > > Hi Paul, > >=20 > > Paul Sexton writes: > >=20 > > > I think there's an error in 'org-without-partial-completion' in org-m= acs.el. > > > The variable pc-mode gets bound to the value of partial-completion-mo= de - but=20 > > > this is a VARIABLE (t if that mode is enabled). Funcalling the value = of=20 > > > the variable produces an error, unsurprisingly. This breaks insertion= of=20 > > > properties with 'org-set-property'.=20 > > > > > > 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 add= ed > > > (unwind-protect > > > (progn > > > (when pc-mode (funcall pc-mode -1)) > > > ,@body) > > > (when pc-mode (funcall pc-mode 1))))) > >=20 > > I've just reverted this modification, per Sebastian report. > >=20 > > Can you be more precise about the problem it creates with > > org-set-property? > >=20 > > Can you check if this version fixes the problems, if any? > >=20 > > #+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 >=20 > 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. >=20 > http://www.gnu.org/software/emacs/elisp/html_node/Compiling-Macros.html#C= ompiling-Macros >=20 > #+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=E2=80=94they would be computed at compile time, which= is > not useful. > #+end_quote >=20 > What about this: >=20 > #+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 >=20 > 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 --=20 OpenPGP... 0x99ADB83B5A4478E6 Jabber.... dmjena@jabber.org Email..... dmaus@ictsoc.de --pgp-sign-Multipart_Sat_Jul__2_09:34:37_2011-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iF4EABEIAAYFAk4Oyg0ACgkQma24O1pEeOZ3bQEArrwk7qW1i9UDxfq1UK6rdFni JubvizcUp/Cg91dp968A/j9we+FWDTq2bBpL7qYxgWuRzxncM4JFOqo2W/MwTbRn =bl5C -----END PGP SIGNATURE----- --pgp-sign-Multipart_Sat_Jul__2_09:34:37_2011-1--