help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: My humble additions to AUCTeX


From: Marcin Borkowski
Subject: Re: My humble additions to AUCTeX
Date: Mon, 13 Jan 2014 19:11:57 +0100

Dnia 2014-01-13, o godz. 08:35:32
jack-mac <duthen.mac@gmail.com> napisał(a):

> 
> Le lundi 13 janvier 2014 00:28:18 UTC+1, Marcin Borkowski a écrit :
> > Also, I still consider myself an Elisp newbie, so it is well
> > possible that I did violate some conventions ar good style...
> > 
> > http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
> 
> In this file, you wrote:
> (defun TeX+-letter (&optional at-is-letter)
>   "Returns a character class matching letters (including \"@\" if
>   AT-IS-LETTER is true)."
>   (concat "a-zA-Z"
>           (if at-is-letter "@")))
> 
> (defun TeX+-looking-at-letter (&optional at-is-letter)
>   "Returns t if the point is at a letter (including \"@\" if
> AT-IS-LETTER; default is not)."
>   (looking-at (concat "[" (TeX+-letter at-is-letter) "]")))
> 
> 
> These function create a new string each time they are called (even if
> at-is-letter is nil).
> 
> For efficiency purpose, I would suggest to "compile" them by hand
> into something like:
> 
> (defconst TeX+-letter-ccml        "a-zA-Z"
>   "A character class matching letters")
> 
> (defconst TeX+-letter-and-at-ccml (concat TeX+-letter-ccml "@")
>   "A character class matching letters including \"@\"")
> 
> (defconst TeX+-letter-re          (concat "[" TeX+-letter-ccml
> "]") "A regexp for character class matching letters")
> 
> (defconst TeX+-letter-and-at-re   (concat "[" TeX+-letter-and-at-ccml
> "]") "A regexp for character class matching letters including \"@\"")
> 
> (defun TeX+-letter (&optional at-is-letter)
>   "Returns a character class matching letters (including \"@\" if
>   AT-IS-LETTER is true)."
>   (if at-is-letter TeX+-letter-and-at-ccml TeX+-letter-ccml))
> 
> 
> (defun TeX+-looking-at-letter (&optional at-is-letter)
>   "Returns t if the point is at a letter (including \"@\" if
> AT-IS-LETTER; default is not)."
>   (looking-at (if at-is-letter TeX+-letter-and-at-re TeX+-letter-re)))
> 
> HTH
> 
> )jack(

Thanks a lot!  In a case of a trade-of between efficiency and code
legibility, I'm in favor of code legibility (unless actual tests prove
that optimization is really needed), but here I can see no problems
like that.  (Well, apart from the a bit more complex situation of
LaTeX3, where there are more characters with the "letter" catcode in
TeXspeak, but still there are at most 3 cases of what "letter" means.)

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University



reply via email to

[Prev in Thread] Current Thread [Next in Thread]