GNU bug report logs -
#21194
2015-06-01; add support for ffap via kpsewhich
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21194 in the body.
You can then email your comments to 21194 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-auctex <at> gnu.org
:
bug#21194
; Package
auctex
.
(Wed, 05 Aug 2015 17:36:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Nicolas Richard <youngfrog <at> members.fsf.org>
:
New bug report received and forwarded. Copy sent to
bug-auctex <at> gnu.org
.
(Wed, 05 Aug 2015 17:36:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi all,
I'm using the following customizations, which I thought I'd share with
you. As the subject says it, it uses kpsewhich for guessing a filename
at point. It allows to use M-x ffap with point on "geometry" to find
geometry.sty, or with point on "memoir" to find memoir.cls.
It is very quick because it calls kpsewhich only once.
I'm not making this into an actual patch because while it works
fine on my system, it's not ready for inclusion yet. I'm open to
your ideas to make it better and eventually include it.
;; a first step is :
;; don't allow braces as possible characters in a filename (otherwise
;; \input{foo} is seen as a possible filename, instead of just foo)
;; (this is because of a recent change in emacs, see commit
;; ba6c32b6decaa2a72a3d5f854efd513e8e82c118 for detail)
(push '(latex-mode "--:\\\\$+<>@-Z_[:alpha:]~*?" "<@" "@>;.,!:")
ffap-string-at-point-mode-alist)
;; second step is to extend rules for finding file at point, and use kpsewhich
(defun yf/ffap-latex-mode (name)
"ffap function in latex buffers"
(if (file-exists-p name)
name
(let ((curbuf (current-buffer)))
(with-temp-buffer
(let ((suffixes '(".sty" ".cls" ".ltx" ".tex" "" ".ldf"))
(prefixes '("" "beamertheme"
"beamercolortheme"
"beamerfonttheme"
"beamerinnertheme"
"beameroutertheme"))
args)
(setq args (apply #'append (mapcar
(lambda (suffix)
(mapcar
(lambda (prefix)
(concat prefix name suffix))
prefixes))
suffixes)))
(let ((process-environment (buffer-local-value 'process-environment curbuf))
(exec-path (buffer-local-value 'exec-path curbuf)))
(apply #'call-process "kpsewhich" nil t nil args))
(when (< (point-min) (point-max))
(buffer-substring (goto-char (point-min)) (point-at-eol))))))))
;; use the above
(advice-add 'ffap-latex-mode :override 'yf/ffap-latex-mode)
Comments welcome!
Nicolas.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#21194
; Package
auctex
.
(Wed, 05 Aug 2015 18:25:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 21194 <at> debbugs.gnu.org (full text, mbox):
Hi Nicolas!
2015-08-05 19:34 GMT+02:00 Nicolas Richard <youngfrog <at> members.fsf.org>:
> Hi all,
>
> I'm using the following customizations, which I thought I'd share with
> you. As the subject says it, it uses kpsewhich for guessing a filename
> at point. It allows to use M-x ffap with point on "geometry" to find
> geometry.sty, or with point on "memoir" to find memoir.cls.
>
> It is very quick because it calls kpsewhich only once.
>
> I'm not making this into an actual patch because while it works
> fine on my system, it's not ready for inclusion yet. I'm open to
> your ideas to make it better and eventually include it.
>
> ;; a first step is :
> ;; don't allow braces as possible characters in a filename (otherwise
> ;; \input{foo} is seen as a possible filename, instead of just foo)
> ;; (this is because of a recent change in emacs, see commit
> ;; ba6c32b6decaa2a72a3d5f854efd513e8e82c118 for detail)
>
> (push '(latex-mode "--:\\\\$+<>@-Z_[:alpha:]~*?" "<@" "@>;.,!:")
> ffap-string-at-point-mode-alist)
>
> ;; second step is to extend rules for finding file at point, and use kpsewhich
>
> (defun yf/ffap-latex-mode (name)
> "ffap function in latex buffers"
> (if (file-exists-p name)
> name
> (let ((curbuf (current-buffer)))
> (with-temp-buffer
> (let ((suffixes '(".sty" ".cls" ".ltx" ".tex" "" ".ldf"))
> (prefixes '("" "beamertheme"
> "beamercolortheme"
> "beamerfonttheme"
> "beamerinnertheme"
> "beameroutertheme"))
> args)
> (setq args (apply #'append (mapcar
> (lambda (suffix)
> (mapcar
> (lambda (prefix)
> (concat prefix name suffix))
> prefixes))
> suffixes)))
> (let ((process-environment (buffer-local-value 'process-environment curbuf))
> (exec-path (buffer-local-value 'exec-path curbuf)))
> (apply #'call-process "kpsewhich" nil t nil args))
> (when (< (point-min) (point-max))
> (buffer-substring (goto-char (point-min)) (point-at-eol))))))))
>
> ;; use the above
> (advice-add 'ffap-latex-mode :override 'yf/ffap-latex-mode)
>
> Comments welcome!
I like this idea, indeed in my init file I've something similar:
--8<---------------cut here---------------start------------->8---
(defun mg-TeX-kpsewhich-find-file (&optional name)
"Visit file associated to NAME searching for it with kpsewhich.
If NAME is nil prompt for a file name. If there is an active
region, use it as initial input. When it is called with
\\[universal-argument] prefix, visit file in another window, in
the current one otherwise."
(interactive)
(if (executable-find "kpsewhich")
(let* ((fun (if current-prefix-arg 'find-file-other-window 'find-file))
(default-directory (TeX-master-directory))
(name (or name (TeX-read-string
"File name: "
(if (TeX-active-mark)
(buffer-substring-no-properties
(region-beginning) (region-end))))))
(file (replace-regexp-in-string
"[\n\r]*\\'" ""
(shell-command-to-string (concat "kpsewhich " name)))))
(if (and (not (zerop (length file))) (file-exists-p file))
(funcall fun file)
(message (concat "File " name " not found."))))
(message "Kpsewhich not available.")))
;; From an original idea of John Wickerson and a first simple implementation of
;; David Carlisle: http://tex.stackexchange.com/q/113376
(defun mg-LaTeX-find-file-at-point ()
"Visit LaTeX file searching for it with kpsewhich.
File basename is guessed from text around point and its extension
is guessed from current macro. When it is called with
\\[universal-argument] prefix, visit file in another window, in
the current one otherwise.
See also `mg-TeX-kpsewhich-find-file'."
(interactive)
(let* ((file-name-regexp "-~/A-Za-z0-9_.$#%:+")
;; Get filename at point.
(name
;; Check whether character at point is a valid file name
;; character.
(if (string-match (concat "[" file-name-regexp "]")
(string (char-after)))
(save-excursion
(skip-chars-backward file-name-regexp)
(looking-at (concat "\\([" file-name-regexp "]+\\)"))
(TeX-match-buffer 1))))
;; Get current macro once.
(current-macro (TeX-current-macro))
;; Guess file extension based on current macro.
(extension (cond
((or (equal "usepackage" current-macro)
(equal "RequirePackage" current-macro)
(equal "RequirePackageWithOptions" current-macro))
".sty")
((or (equal "documentclass" current-macro)
(equal "documentstyle" current-macro)
(equal "LoadClass" current-macro)
(equal "LoadClassWithOptions" current-macro))
".cls")
((equal "include" current-macro) ".tex")
((equal "input" current-macro)
;; `input' macro accepts a file name with extension, in
;; that case use an empty but non-nil extension.
(if (and name (file-name-extension name)) "" ".tex"))
((equal "bibliography" current-macro) ".bib")
((equal "addbibresource" current-macro) "")
(t nil))))
(if (and name extension)
(mg-TeX-kpsewhich-find-file (concat name extension))
(message "Cannot guess file name at point."))))
--8<---------------cut here---------------end--------------->8---
This is smarter than your function in the sense that it looks at
current macro to determine the extension (didn't test it, but I think
your implementation would open "article.sty" instead of the more
sensible "article.cls" with point on "article"). You can try to
improve your implementation stealing my code ;-)
Bye,
Mosè
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#21194
; Package
auctex
.
(Wed, 05 Aug 2015 18:32:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 21194 <at> debbugs.gnu.org (full text, mbox):
Nicolas Richard <youngfrog <at> members.fsf.org> writes:
Hi Nicolas,
> I'm using the following customizations, which I thought I'd share with
> you. As the subject says it, it uses kpsewhich for guessing a filename
> at point. It allows to use M-x ffap with point on "geometry" to find
> geometry.sty, or with point on "memoir" to find memoir.cls.
>
> It is very quick because it calls kpsewhich only once.
>
> I'm not making this into an actual patch because while it works fine
> on my system, it's not ready for inclusion yet. I'm open to your
> ideas to make it better and eventually include it.
It's definitely useful but...
> ;; use the above
> (advice-add 'ffap-latex-mode :override 'yf/ffap-latex-mode)
...since you override the Emacs builtin `ffap-latex-mode' function, why
not improve ffap.el by making it use `kpsewhich' if that's available?
Then this feature would be available to all emacs users, not only to
AUCTeX users. Of course, I'd happily add a menu entry and/or keybinding
for it in AUCTeX.
Bye,
Tassilo
Reply sent
to
Nicolas Richard <youngfrog <at> members.fsf.org>
:
You have taken responsibility.
(Sun, 09 Aug 2015 16:50:03 GMT)
Full text and
rfc822 format available.
Notification sent
to
Nicolas Richard <youngfrog <at> members.fsf.org>
:
bug acknowledged by developer.
(Sun, 09 Aug 2015 16:50:04 GMT)
Full text and
rfc822 format available.
Message #16 received at 21194-done <at> debbugs.gnu.org (full text, mbox):
Hello Mosè
Mosè Giordano <mose <at> gnu.org> writes:
> This is smarter than your function in the sense that it looks at
> current macro to determine the extension (didn't test it, but I think
> your implementation would open "article.sty" instead of the more
> sensible "article.cls" with point on "article").
Indeed, there are a few ways to confuse my code, but it doesn't bite me
often (I never use article class anyway :p). I've fixed this nonetheless.
I pushed the result to emacs master, so it should make its way to emacs
25.1.
Thanks for your comments.
--
Nico.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#21194
; Package
auctex
.
(Sun, 09 Aug 2015 16:51:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 21194 <at> debbugs.gnu.org (full text, mbox):
Hello Tassilo,
Thanks for your comment.
Tassilo Horn <tsdh <at> gnu.org> writes:
> ...since you override the Emacs builtin `ffap-latex-mode' function, why
> not improve ffap.el by making it use `kpsewhich' if that's available?
Because it's about LaTeX and my brain somehow always associates LaTeX
with AUCTeX. Silly brain. I followed your advice and pushed this to
emacs master just now.
Nicolas.
Information forwarded
to
bug-auctex <at> gnu.org
:
bug#21194
; Package
auctex
.
(Sun, 09 Aug 2015 17:03:01 GMT)
Full text and
rfc822 format available.
Message #22 received at 21194 <at> debbugs.gnu.org (full text, mbox):
Hi Nicolas,
2015-08-09 18:49 GMT+02:00 Nicolas Richard <youngfrog <at> members.fsf.org>:
> Hello Mosè
>
> Mosè Giordano <mose <at> gnu.org> writes:
>> This is smarter than your function in the sense that it looks at
>> current macro to determine the extension (didn't test it, but I think
>> your implementation would open "article.sty" instead of the more
>> sensible "article.cls" with point on "article").
>
> Indeed, there are a few ways to confuse my code, but it doesn't bite me
> often (I never use article class anyway :p). I've fixed this nonetheless.
>
> I pushed the result to emacs master, so it should make its way to emacs
> 25.1.
Cool! Thank you!
Bye,
Mosè
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 07 Sep 2015 11:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 9 years and 291 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.