unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Patches on ffap (mainly for latex buffers)
@ 2015-08-06 11:54 Nicolas Richard
  2015-08-07 15:47 ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Richard @ 2015-08-06 11:54 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Augment-docstring-of-ffap-string-at-point-mode-alist.patch --]
[-- Type: text/x-diff, Size: 1026 bytes --]

From 5bc0c01b9f6219404dc4211a8b95704717211b3d Mon Sep 17 00:00:00 2001
From: Nicolas Richard <youngfrog@members.fsf.org>
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


[-- Attachment #3: Type: text/plain, Size: 161 bytes --]


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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0002-Remove-useless-backslashes-from-ffap-string-at-point.patch --]
[-- Type: text/x-diff, Size: 1048 bytes --]

From d04be6d562ea469cb46434754212d24583fa682c Mon Sep 17 00:00:00 2001
From: Nicolas Richard <youngfrog@members.fsf.org>
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 "--:=&?$+@-Z_[:alpha:]~#,%;*()!'" "^[0-9a-zA-Z]" ":;.,!?")
     ;; Find a string that does *not* contain a colon:
-- 
2.4.5


[-- Attachment #5: Type: text/plain, Size: 67 bytes --]


The third patch allows ffap to use kpsewhich when it's available.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0003-lisp-ffap.el-ffap-latex-mode-Use-kpsewhich-if-availa.patch --]
[-- Type: text/x-diff, Size: 4158 bytes --]

From 53ceb084b4aa7ccc0670d613d8405063b9d890d7 Mon Sep 17 00:00:00 2001
From: Nicolas Richard <youngfrog@members.fsf.org>
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 @@
 
 \f
 ;;; 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


[-- Attachment #7: Type: text/plain, Size: 234 bytes --]


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}.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: 0004-ffap-disallow-braces-in-filenames-for-tex-modes.patch --]
[-- Type: text/x-diff, Size: 1001 bytes --]

From cbe06f095afe103f23ff3eef0d344eb58b224a91 Mon Sep 17 00:00:00 2001
From: Nicolas Richard <youngfrog@members.fsf.org>
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


[-- Attachment #9: Type: text/plain, Size: 10 bytes --]


-- 
Nico

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-08-09 16:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-06 11:54 Patches on ffap (mainly for latex buffers) Nicolas Richard
2015-08-07 15:47 ` Stefan Monnier
2015-08-07 20:09   ` Nicolas Richard
2015-08-07 21:34     ` Stefan Monnier
2015-08-08  6:48       ` Nicolas Richard
2015-08-09 12:44       ` Nicolas Richard
2015-08-09 16:22         ` Stefan Monnier
2015-08-09 16:46           ` Nicolas Richard

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).