[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patches on ffap (mainly for latex buffers)
From: |
Nicolas Richard |
Subject: |
Patches on ffap (mainly for latex buffers) |
Date: |
Thu, 06 Aug 2015 13:54:57 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Hello,
I'd like to suggest a few patches for ffap (find-file-at-point). The
first two are rather non-intrusive, but I don't want to push the last
two without hearing opinions first.
>From 5bc0c01b9f6219404dc4211a8b95704717211b3d Mon Sep 17 00:00:00 2001
From: Nicolas Richard <address@hidden>
Date: Wed, 5 Aug 2015 18:57:20 +0200
Subject: [PATCH 1/4] Augment docstring of ffap-string-at-point-mode-alist
* lisp/ffap.el (ffap-string-at-point-mode-alist): Describe how BEG
and END are handled.
---
lisp/ffap.el | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 81cba07..a2f7253 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1020,7 +1020,8 @@ possibly a major-mode name, or one of the symbols
Function `ffap-string-at-point' uses the data fields as follows:
1. find a maximal string of CHARS around point,
2. strip BEG chars before point from the beginning,
-3. strip END chars after point from the end.")
+3. strip END chars after point from the end.
+The arguments BEG and END are handled as described in `skip-chars-forward'.")
(defvar ffap-string-at-point nil
;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95.
--
2.4.5
The second patch removes backslashes (meant as escaping) which are
useless : BEG end END are not regexes, they are the inside of a
skip-chars-forward/backward.
>From d04be6d562ea469cb46434754212d24583fa682c Mon Sep 17 00:00:00 2001
From: Nicolas Richard <address@hidden>
Date: Wed, 5 Aug 2015 19:04:44 +0200
Subject: [PATCH 2/4] Remove useless backslashes from
ffap-string-at-point-mode-alist
* lisp/ffap.el (ffap-string-at-point-mode-alist): Remove useless and
misleading backslashes from default value.
---
lisp/ffap.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/ffap.el b/lisp/ffap.el
index a2f7253..26a1f88 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1004,7 +1004,7 @@ If a given RFC isn't in these then `ffap-rfc-path' is
offered."
;; Slightly controversial decisions:
;; * strip trailing "@" and ":"
;; * no commas (good for latex)
- (file "--:\\\\$\\{\\}+<>@-Z_[:alpha:]~*?" "<@" "@>;.,!:")
+ (file "--:\\\\${}+<>@-Z_[:alpha:]~*?" "<@" "@>;.,!:")
;; An url, or maybe a email/news message-id:
(url "--:=&address@hidden:alpha:]~#,%;*()!'" "^[0-9a-zA-Z]" ":;.,!?")
;; Find a string that does *not* contain a colon:
--
2.4.5
The third patch allows ffap to use kpsewhich when it's available.
>From 53ceb084b4aa7ccc0670d613d8405063b9d890d7 Mon Sep 17 00:00:00 2001
From: Nicolas Richard <address@hidden>
Date: Thu, 6 Aug 2015 10:54:50 +0200
Subject: [PATCH 3/4] * lisp/ffap.el (ffap-latex-mode): Use kpsewhich if
available
---
lisp/ffap.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 26a1f88..a98919c 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -90,7 +90,6 @@
;;; Todo list:
-;; * use kpsewhich
;; * let "/dir/file#key" jump to key (tag or regexp) in /dir/file
;; * find file of symbol if TAGS is loaded (like above)
;; * break long menus into multiple panes (like imenu?)
@@ -917,9 +916,60 @@ If t, `ffap-tex-init' will initialize this when needed.")
(ffap-locate-file name '(".tex" "") ffap-tex-path))
(defun ffap-latex-mode (name)
- (ffap-tex-init)
- ;; only rare need for ""
- (ffap-locate-file name '(".cls" ".sty" ".tex" "") ffap-tex-path))
+ "`ffap' function suitable for latex buffers"
+ (cond ((file-exists-p name)
+ name)
+ ((not (executable-find "kpsewhich"))
+ (ffap-tex-init)
+ (ffap-locate-file name '(".cls" ".sty" ".tex" "") ffap-tex-path))
+ (t
+ (let ((curbuf (current-buffer))
+ (suffixes '(".sty" ".cls" ".ltx" ".tex" "" ".ldf"))
+ (prefixes '(""
+ "beamertheme"
+ "beamercolortheme"
+ "beamerfonttheme"
+ "beamerinnertheme"
+ "beameroutertheme"))
+ (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))
+ (point-at-bol)
+ t))
+ (push (cdr (assoc (match-string 0) ; i.e. "(TeX-current-macro)"
+ preferred-suffix-rules))
+ suffixes))
+ (setq kpsewhich-args (apply #'append (mapcar
+ (lambda (suffix)
+ (mapcar
+ (lambda (prefix)
+ (concat prefix name
suffix))
+ prefixes))
+ suffixes)))
+ (with-temp-buffer
+ (let ((process-environment (buffer-local-value
'process-environment curbuf))
+ (exec-path (buffer-local-value 'exec-path curbuf)))
+ (apply #'call-process "kpsewhich" nil t nil kpsewhich-args))
+ (when (< (point-min) (point-max))
+ (buffer-substring (goto-char (point-min)) (point-at-eol))))))))
(defun ffap-tex (name)
(ffap-tex-init)
--
2.4.5
The fourth (and last) patch fixes a problem introduced in commit
ba6c32b6decaa2a72a3d5f854efd513e8e82c118, where braces were allowed in
filenames. This is not good for TeX and friends, where braces are
delimiters, as in \input{foo}.
>From cbe06f095afe103f23ff3eef0d344eb58b224a91 Mon Sep 17 00:00:00 2001
From: Nicolas Richard <address@hidden>
Date: Thu, 6 Aug 2015 13:05:11 +0200
Subject: [PATCH 4/4] ffap: disallow braces in filenames for tex modes
* lisp/ffap.el (ffap-string-at-point-mode-alist): Don't allow
braces in tex-related modes.
---
lisp/ffap.el | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lisp/ffap.el b/lisp/ffap.el
index a98919c..2f02aae 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1063,6 +1063,9 @@ If a given RFC isn't in these then `ffap-rfc-path' is
offered."
(machine "-[:alnum:]." "" ".")
;; Mathematica paths: allow backquotes
(math-mode ",-:$+<>@-Z_[:lower:]~`" "<" "@>;.,!?`:")
+ ;; (La)TeX: don't allow braces
+ (latex-mode "--:\\\\$+<>@-Z_[:alpha:]~*?" "<@" "@>;.,!:")
+ (tex-mode "--:\\\\$+<>@-Z_[:alpha:]~*?" "<@" "@>;.,!:")
)
"Alist of (MODE CHARS BEG END), where MODE is a symbol,
possibly a major-mode name, or one of the symbols
--
2.4.5
--
Nico
- Patches on ffap (mainly for latex buffers),
Nicolas Richard <=
- Re: Patches on ffap (mainly for latex buffers), Stefan Monnier, 2015/08/07
- Re: Patches on ffap (mainly for latex buffers), Nicolas Richard, 2015/08/07
- Re: Patches on ffap (mainly for latex buffers), Stefan Monnier, 2015/08/07
- Re: Patches on ffap (mainly for latex buffers), Nicolas Richard, 2015/08/08
- Re: Patches on ffap (mainly for latex buffers), Nicolas Richard, 2015/08/09
- Re: Patches on ffap (mainly for latex buffers), Stefan Monnier, 2015/08/09
- Re: Patches on ffap (mainly for latex buffers), Nicolas Richard, 2015/08/09