* Adding a feature to ffap (find-file-at-point) in LaTeX-mode
@ 2024-11-30 4:09 Leo Stein
0 siblings, 0 replies; only message in thread
From: Leo Stein @ 2024-11-30 4:09 UTC (permalink / raw)
To: auctex-devel, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 5022 bytes --]
Hi all,
I have a feature that I got working with my very rudimentary elisp, and
would consider submitting it as a patch, but I suspect it needs some work
before it can be accepted (as I said, my elisp is very basic). I would like
ffap to parse some extra path info out of my LaTeX buffer, and use that
extra path to search for a file within an \input{othertexfile} command.
This extra path info is in a form like the \graphicspath command of
graphicx, or equivalently the TeX internal macro \input@path.
But, there needs to be a separation between the duties of ffap and the
duties of any AUCTeX style-specific code. Probably there is a better
solution than the following, but here is what I thought of. AUCTeX is
responsible for some LaTeX-parse-extra-path function, which can e.g. check
the contents of TeX-active-styles and call style-specific functions.
Meanwhile ffap-latex-mode needs to be generalized to potentially call such
an AUCTeX function, if it exists. Example:
(defun ffap-latex-mode (name)
> "`ffap' function suitable for latex buffers.
> This uses the program kpsewhich if available. In this case, the
> variable `ffap-latex-guess-rules' is used for building a filename
> out of NAME."
> (let ((extra-path (if (fboundp 'LaTeX-parse-extra-path)
> (LaTeX-parse-extra-path)
> '())))
> (cond ((file-exists-p name)
> name)
> ((not (executable-find "kpsewhich"))
> (ffap-tex-init)
> (ffap-locate-file name '(".cls" ".sty" ".tex" "")
> (append extra-path ffap-tex-path)))
> (t
> (let ((curbuf (current-buffer))
> (guess-rules ffap-latex-guess-rules)
> (preferred-suffix-rules '(("input" . ".tex")
> ("include" . ".tex")
> ("usepackage" . ".sty")
> ("RequirePackageWithOptions" .
> ".sty")
> ("RequirePackage" . ".sty")
> ("documentclass" . ".cls")
> ("documentstyle" . ".cls")
> ("LoadClass" . ".cls")
> ("LoadClassWithOptions" .
> ".cls")
> ("bibliography" . ".bib")
> ("addbibresource" . ""))))
> ;; We now add preferred suffix in front of suffixes.
> (when
> ;; The condition is essentially:
> ;; (assoc (TeX-current-macro)
> ;; (mapcar 'car preferred-suffix-rules))
> ;; but (TeX-current-macro) can take time, so we just
> ;; check if one of the `car' in preferred-suffix-rules
> ;; is found before point on the current line. It
> ;; should cover most cases.
> (save-excursion
> (re-search-backward (regexp-opt
> (mapcar 'car
> preferred-suffix-rules))
> (line-beginning-position)
> t))
> (push (cons "" (cdr (assoc (match-string 0) ; i.e.
> "(TeX-current-macro)"
> preferred-suffix-rules)))
> guess-rules))
> (with-temp-buffer
> (let ((process-environment (buffer-local-value
> 'process-environment curbuf))
> (exec-path (buffer-local-value 'exec-path curbuf))
> (extra-path-string (mapconcat 'identity extra-path
> ":"))
> (args (mapcar (lambda (rule)
> (concat (car rule) name (cdr rule)))
> guess-rules)))
> (apply #'call-process "kpsewhich" nil t nil args)
> (if (not (string= "" extra-path-string))
> (apply #'call-process "kpsewhich" nil t nil "-path"
> extra-path-string args)))
> (when (< (point-min) (point-max))
> (buffer-substring (goto-char (point-min))
> (line-end-position)))))))))
The function LaTeX-parse-extra-path returns a list of strings, which are
used in the two possible search methods (without or with kpsewhich). If
using kpsewhich, we have to call it once for searching system default paths
(e.g. for installed style or class files), and a second time for searching
user's extra paths as parsed out of the their buffer (the call-process is
skipped if there are no extra paths).
My main question is how this should be made more idiomatic for potential
inclusion in ffap.el; and if there is a better way for ffap.el and AUCTeX
to cooperate with each other.
Thanks in advance,
Leo
[-- Attachment #2: Type: text/html, Size: 6478 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-11-30 4:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 4:09 Adding a feature to ffap (find-file-at-point) in LaTeX-mode Leo Stein
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).