all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode
Date: Mon, 31 Aug 2015 11:34:18 +0200	[thread overview]
Message-ID: <87egijls2t.fsf@gnu.org> (raw)
In-Reply-To: <jwv613zs6r8.fsf-monnier+emacsdiffs@gnu.org> (Stefan Monnier's message of "Fri, 28 Aug 2015 12:45:38 -0400")

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> +    (if (fboundp 'add-function)
>> +	(add-function :override (local 'prettify-symbols-compose-predicate)
>> +		      #'tex--prettify-symbols-compose-p)
>> +      (set (make-local-variable 'prettify-symbols-compose-predicate)
>> +	   #'tex--prettify-symbols-compose-p)))
>
> If you compile this code in Emacs-24.1 and then run it in Emacs-24.4
> it's signal an error, because add-function is a macro that will not have
> been expanded.
>
> I recently solved the same problem in elpa/packages/dts-mode with
> dts--using-macro.

Is that what I should use?  I guess you also know how to fix the FIXME
about the indentation, right?

--8<---------------cut here---------------start------------->8---
1 file changed, 22 insertions(+), 3 deletions(-)
 tex.el | 25 ++++++++++++++++++++++---

modified   tex.el
@@ -578,6 +578,25 @@ the name of the file being processed, with an optional extension."
 
 ;;; Portability.
 
+(defmacro TeX--if-macro-fboundp (name then &rest else)
+  "Execute THEN if macro NAME is bound and ELSE otherwise.
+This essentially equivalent to
+
+  (if (fboundp 'name) then else)
+
+but takes care of byte-compilation issues where the byte-code for
+the above could signal an error if it has been compiled with
+emacs 24.1 and then later run by emacs 24.5."
+  ;; FIXME: Is there an easy way to declare that this macro is to be indented
+  ;; exactly as `if'?
+  (declare (indent 1) (debug (symbolp form)))
+  (if (fboundp name)            ;If macro exists at compile-time, just use it.
+      then
+    `(if (fboundp ',name)             ;Else, check if it exists at run-time.
+	 (eval ',then)                ;If it does, then run the then code.
+       ,@(when else
+	   `(eval (progn ',else)))))) ;Otherwise, run the else code.
+
 (require 'easymenu)
 
 (eval-and-compile
@@ -3442,9 +3461,9 @@ The algorithm is as follows:
   (when (and (boundp 'tex--prettify-symbols-alist)
 	     (boundp 'prettify-symbols-compose-predicate))
     (set (make-local-variable 'prettify-symbols-alist) tex--prettify-symbols-alist)
-    (if (fboundp 'add-function)
-	(add-function :override (local 'prettify-symbols-compose-predicate)
-		      #'tex--prettify-symbols-compose-p)
+    (TeX--if-macro-fboundp add-function
+      (add-function :override (local 'prettify-symbols-compose-predicate)
+		    #'tex--prettify-symbols-compose-p)
       (set (make-local-variable 'prettify-symbols-compose-predicate)
 	   #'tex--prettify-symbols-compose-p)))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



  reply	other threads:[~2015-08-31  9:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150828085448.24208.47194@vcs.savannah.gnu.org>
     [not found] ` <E1ZVFQz-0006Kf-Lb@vcs.savannah.gnu.org>
2015-08-28 16:45   ` [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode Stefan Monnier
2015-08-31  9:34     ` Tassilo Horn [this message]
2015-08-31 17:54       ` Stefan Monnier
2015-09-01  6:18         ` Tassilo Horn

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=87egijls2t.fsf@gnu.org \
    --to=tsdh@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.