From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.devel Subject: Patches on ffap (mainly for latex buffers) Date: Thu, 06 Aug 2015 13:54:57 +0200 Message-ID: <87zj244ooe.fsf@members.fsf.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1438862142 17652 80.91.229.3 (6 Aug 2015 11:55:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Aug 2015 11:55:42 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 06 13:55:28 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZNJlW-0005Of-Mv for ged-emacs-devel@m.gmane.org; Thu, 06 Aug 2015 13:55:18 +0200 Original-Received: from localhost ([::1]:44580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNJlU-0005Tb-UI for ged-emacs-devel@m.gmane.org; Thu, 06 Aug 2015 07:55:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNJlJ-0005G8-1s for emacs-devel@gnu.org; Thu, 06 Aug 2015 07:55:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNJlD-0002eO-SL for emacs-devel@gnu.org; Thu, 06 Aug 2015 07:55:04 -0400 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:28682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNJlD-0002e5-Fg for emacs-devel@gnu.org; Thu, 06 Aug 2015 07:54:59 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsEFAH9Kw1WkD4Xx/2dsb2JhbABbgkmCD4JVpwQBAQEBAQEGmzECghQBAQEBAQGBC4QjAQKBFRQDAQIKNAEEOyEaiBSme6ZQhh+JVAIRAUAehCYFjFGIMJUnkR8mg388MYEFCReBJwEBAQ Original-Received: from mathsrv4.ulb.ac.be (HELO localhost) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 06 Aug 2015 13:54:58 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:188496 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Augment-docstring-of-ffap-string-at-point-mode-alist.patch >From 5bc0c01b9f6219404dc4211a8b95704717211b3d Mon Sep 17 00:00:00 2001 From: Nicolas Richard 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 --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Remove-useless-backslashes-from-ffap-string-at-point.patch >From d04be6d562ea469cb46434754212d24583fa682c Mon Sep 17 00:00:00 2001 From: Nicolas Richard 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 --=-=-= Content-Type: text/plain The third patch allows ffap to use kpsewhich when it's available. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-lisp-ffap.el-ffap-latex-mode-Use-kpsewhich-if-availa.patch >From 53ceb084b4aa7ccc0670d613d8405063b9d890d7 Mon Sep 17 00:00:00 2001 From: Nicolas Richard 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 --=-=-= Content-Type: text/plain 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}. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0004-ffap-disallow-braces-in-filenames-for-tex-modes.patch >From cbe06f095afe103f23ff3eef0d344eb58b224a91 Mon Sep 17 00:00:00 2001 From: Nicolas Richard 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 --=-=-= Content-Type: text/plain -- Nico --=-=-=--