From: "Arne Jørgensen" <arne@arnested.dk>
Cc: Thien-Thi Nguyen <ttn@gnu.org>,
Stefan Monnier <monnier@iro.umontreal.ca>,
Lute Kamstra <Lute.Kamstra.lists@xs4all.nl>,
Richard Stallman <rms@gnu.org>
Subject: Re: latexenc-find-file-coding-system is slow.
Date: Wed, 11 May 2005 19:21:24 +0200 [thread overview]
Message-ID: <87sm0tu19n.fsf@arnested.dk> (raw)
In-Reply-To: 87psvykmpp.fsf@xs4all.nl
[-- Attachment #1: Type: text/plain, Size: 3661 bytes --]
Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
> [For some reason, I didn't see your message on emacs-devel.]
Neither did I. It got lost again as most of my mail to @gnu.org
addresses do. This is posted through Gmane instead.
> Arne Jørgensen <arne@arnested.dk> writes:
[...]
> I think there a some minor problems with the details of the
> implementation:
>
>> Index: lisp/international/latexenc.el
>> ===================================================================
>> RCS file: /cvsroot/emacs/emacs/lisp/international/latexenc.el,v
>> retrieving revision 1.3
>> diff -u -p -r1.3 latexenc.el
>> --- lisp/international/latexenc.el 1 May 2005 11:01:49 -0000 1.3
>> +++ lisp/international/latexenc.el 4 May 2005 18:12:23 -0000
>> @@ -120,24 +120,33 @@ coding system names is determined from `
>> (save-excursion
>> ;; try to find the coding system in this file
>> (goto-char (point-min))
>> - (if (or
>> - (re-search-forward "^[^%\n]*\\\\inputencoding{\\(.*\\)}" nil t)
>> - (re-search-forward "^[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{inputenc}" nil t))
>> - (let* ((match (match-string 1))
>> - (sym (intern match)))
>> - (when (latexenc-inputenc-to-coding-system match)
>> - (setq sym (latexenc-inputenc-to-coding-system match))
>> - (when (coding-system-p sym)
>> - sym
>> - (if (and (require 'code-pages nil t) (coding-system-p sym))
>> - sym
>> - 'undecided))))
>> + (if (catch 'cs
>> + (let ((case-fold-search nil))
>> + (while (search-forward "inputenc" nil t)
>> + (goto-char (match-beginning 0))
>> + (beginning-of-line)
>> + (if (or (looking-at "[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{\\(.*,\\)?inputenc\\(,.*\\)?}")
>
> That also matches something like:
>
> \usepackage[opt]{package} % don't use {package,inputenc}
Right. I should be fixed now.
>> + (looking-at "[^%\n]*\\\\inputencoding{\\(.*\\)}"))
>> + (throw 'cs (match-string 1))
>
> Why throw (match-string 1) instead of t?
You're right.
>> + (goto-char (match-end 0))))))
>> + (let* ((match (match-string 1))
>> + (sym (intern match)))
>> + (when (latexenc-inputenc-to-coding-system match)
>> + (setq sym (latexenc-inputenc-to-coding-system match)))
>> + (when (coding-system-p sym)
>> + sym
>> + (if (and (require 'code-pages nil t) (coding-system-p sym))
>> + sym
>> + 'undecided)))
>> ;; else try to find it in the master/main file
>> - (let (latexenc-main-file)
>> + (let (latexenc-main-file
>> + bound)
>> ;; is there a TeX-master or tex-main-file in the local variable section
>> (unless latexenc-dont-use-TeX-master-flag
>> (goto-char (point-max))
>> - (when (re-search-backward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
>> + (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
>> + (setq bound (search-forward "Local Variables:" nil t))
>> + (when (re-search-forward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
>> (let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2))))
>> (if (file-exists-p file)
>> (setq latexenc-main-file file)
>
> You don't seem to use the variable bound.
No. It's gone now. (I was probably tired).
> Could you also write a ChangeLog entry for your patch?
Done.
New patch attached.
Thanks and kind regard,
--
Arne Jørgensen <http://arnested.dk/>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: latexenc.patch --]
[-- Type: text/x-patch, Size: 3415 bytes --]
Index: lisp/ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.7484
diff -u -p -r1.7484 ChangeLog
--- lisp/ChangeLog 11 May 2005 16:42:40 -0000 1.7484
+++ lisp/ChangeLog 11 May 2005 17:14:03 -0000
@@ -1,3 +1,11 @@
+2005-05-11 Arne J^[,Ax^[(Brgensen <arne@arnested.dk>
+
+ * international/latexenc.el (latexenc-find-file-coding-system):
+ Avoid `re-search-forward' when looking for input encoding because
+ of speed and safety. Better regexp's for recognizing input
+ encoding. Limit a search for TeX-master/tex-main-file to the local
+ variable section.
+
2005-05-11 Stefan Monnier <monnier@iro.umontreal.ca>
* files.el (executable-find): Move from executable.el. Use locate-file.
Index: lisp/international/latexenc.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/international/latexenc.el,v
retrieving revision 1.3
diff -u -p -r1.3 latexenc.el
--- lisp/international/latexenc.el 1 May 2005 11:01:49 -0000 1.3
+++ lisp/international/latexenc.el 11 May 2005 17:14:03 -0000
@@ -120,24 +120,32 @@ coding system names is determined from `
(save-excursion
;; try to find the coding system in this file
(goto-char (point-min))
- (if (or
- (re-search-forward "^[^%\n]*\\\\inputencoding{\\(.*\\)}" nil t)
- (re-search-forward "^[^%\n]*\\\\usepackage\\[\\(.*\\)\\]{inputenc}" nil t))
- (let* ((match (match-string 1))
- (sym (intern match)))
- (when (latexenc-inputenc-to-coding-system match)
- (setq sym (latexenc-inputenc-to-coding-system match))
- (when (coding-system-p sym)
- sym
- (if (and (require 'code-pages nil t) (coding-system-p sym))
- sym
- 'undecided))))
+ (if (catch 'cs
+ (let ((case-fold-search nil))
+ (while (search-forward "inputenc" nil t)
+ (goto-char (match-beginning 0))
+ (beginning-of-line)
+ (if (or (looking-at "[^%\n]*\\\\usepackage\\[\\([^]]*\\)\\]{\\([^}]*,\\)?inputenc\\(,[^}]*\\)?}")
+ (looking-at "[^%\n]*\\\\inputencoding{\\([^}]*\\)}"))
+ (throw 'cs t)
+ (goto-char (match-end 0))))))
+ (let* ((match (match-string 1))
+ (sym (intern match)))
+ (when (latexenc-inputenc-to-coding-system match)
+ (setq sym (latexenc-inputenc-to-coding-system match)))
+ (when (coding-system-p sym)
+ sym
+ (if (and (require 'code-pages nil t) (coding-system-p sym))
+ sym
+ 'undecided)))
;; else try to find it in the master/main file
(let (latexenc-main-file)
;; is there a TeX-master or tex-main-file in the local variable section
(unless latexenc-dont-use-TeX-master-flag
(goto-char (point-max))
- (when (re-search-backward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
+ (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
+ (search-forward "Local Variables:" nil t)
+ (when (re-search-forward "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\"" nil t)
(let ((file (concat (file-name-directory (nth 1 arg-list)) (match-string 2))))
(if (file-exists-p file)
(setq latexenc-main-file file)
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
next prev parent reply other threads:[~2005-05-11 17:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1D7MTJ-0002Jj-BJ@fencepost.gnu.org>
2005-04-26 12:07 ` Your Emacs changes Arne Jørgensen
2005-04-28 11:58 ` Thien-Thi Nguyen
2005-04-29 12:11 ` latexenc-find-file-coding-system is slow. (was: Your Emacs changes) Lute Kamstra
2005-04-29 14:57 ` latexenc-find-file-coding-system is slow Arne Jørgensen
2005-04-29 15:48 ` Lute Kamstra
2005-04-29 16:13 ` Stefan Monnier
[not found] ` <877jil8rz5.fsf@arnested.dk>
2005-04-29 17:19 ` Lute Kamstra
2005-04-30 8:08 ` David Kastrup
2005-05-01 11:08 ` Lute Kamstra
2005-05-01 12:07 ` latexenc-find-file-coding-system is slow. (was: Your Emacs changes) Richard Stallman
[not found] ` <871x8m96p6.fsf@arnested.dk>
2005-05-11 11:48 ` latexenc-find-file-coding-system is slow Lute Kamstra
2005-05-11 17:21 ` Arne Jørgensen [this message]
2005-05-11 23:07 ` Lute Kamstra
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sm0tu19n.fsf@arnested.dk \
--to=arne@arnested.dk \
--cc=Lute.Kamstra.lists@xs4all.nl \
--cc=monnier@iro.umontreal.ca \
--cc=rms@gnu.org \
--cc=ttn@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).