all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Leo Stein <leo.stein@gmail.com>
To: auctex-devel@gnu.org, emacs-devel@gnu.org
Subject: Adding a feature to ffap (find-file-at-point) in LaTeX-mode
Date: Fri, 29 Nov 2024 22:09:03 -0600	[thread overview]
Message-ID: <CAE56pjFWVL29MdK3ZVWWghMn65eWGYPzDW-rMDYnD0bkALKdVA@mail.gmail.com> (raw)

[-- 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 --]

                 reply	other threads:[~2024-11-30  4:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAE56pjFWVL29MdK3ZVWWghMn65eWGYPzDW-rMDYnD0bkALKdVA@mail.gmail.com \
    --to=leo.stein@gmail.com \
    --cc=auctex-devel@gnu.org \
    --cc=emacs-devel@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 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.