[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symb
From: |
Tassilo Horn |
Subject: |
Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode |
Date: |
Mon, 31 Aug 2015 11:34:18 +0200 |
User-agent: |
Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> 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