* Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode
[not found] ` <E1ZVFQz-0006Kf-Lb@vcs.savannah.gnu.org>
@ 2015-08-28 16:45 ` Stefan Monnier
2015-08-31 9:34 ` Tassilo Horn
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2015-08-28 16:45 UTC (permalink / raw)
To: emacs-devel; +Cc: Tassilo Horn
> + (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.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode
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
2015-08-31 17:54 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2015-08-31 9:34 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode
2015-08-31 9:34 ` Tassilo Horn
@ 2015-08-31 17:54 ` Stefan Monnier
2015-09-01 6:18 ` Tassilo Horn
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2015-08-31 17:54 UTC (permalink / raw)
To: emacs-devel
>> I recently solved the same problem in elpa/packages/dts-mode with
>> dts--using-macro.
> Is that what I should use?
I think for this use-case, it looks OK, yes.
> I guess you also know how to fix the FIXME about the
> indentation, right?
Maybe (declare (indent if)) works?
> + `(eval (progn ',else)))))) ;Otherwise, run the else code.
I think you can just use ‘else’ here without going through ‘eval’.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/auctex 7e762b9 09/10: Add support for prettify-symbols-mode
2015-08-31 17:54 ` Stefan Monnier
@ 2015-09-01 6:18 ` Tassilo Horn
0 siblings, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2015-09-01 6:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> I recently solved the same problem in elpa/packages/dts-mode with
>>> dts--using-macro.
>> Is that what I should use?
>
> I think for this use-case, it looks OK, yes.
Thanks.
>> I guess you also know how to fix the FIXME about the
>> indentation, right?
>
> Maybe (declare (indent if)) works?
No, that gives:
--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (invalid-function if)
if(126797 (3 126761 126784 nil nil nil 0 nil nil (124088 126572 126761)))
lisp-indent-function(126797 (3 126761 126784 nil nil nil 0 nil nil (124088 126572 126761)))
calculate-lisp-indent()
lisp-indent-line()
indent-for-tab-command(nil)
funcall-interactively(indent-for-tab-command nil)
call-interactively(indent-for-tab-command nil nil)
command-execute(indent-for-tab-command)
--8<---------------cut here---------------end--------------->8---
But the definition of `if-let' suggested that I'm looking for (indent 2)
which indeed has the desired effect.
>> + `(eval (progn ',else)))))) ;Otherwise, run the else code.
>
> I think you can just use ‘else’ here without going through ‘eval’.
Even better, thanks.
Bye,
Tassilo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-01 6:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
2015-08-31 17:54 ` Stefan Monnier
2015-09-01 6:18 ` Tassilo Horn
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.