diff options
| author | Nicolas Richard | 2015-08-06 10:54:50 +0200 |
|---|---|---|
| committer | Nicolas Richard | 2015-08-09 18:41:44 +0200 |
| commit | 3b112f6389edd1b55ed32cd4836a1d2cdafb524f (patch) | |
| tree | 98c525bcb24a9ba061e0383c2deac01a9f5b1d0d | |
| parent | 7f1baf2bfa0369c68d41cc178c482d26068e43a4 (diff) | |
| download | emacs-3b112f6389edd1b55ed32cd4836a1d2cdafb524f.tar.gz emacs-3b112f6389edd1b55ed32cd4836a1d2cdafb524f.zip | |
Use kpsewhich in ffap-latex-mode, if available
* lisp/ffap.el (ffap-latex-guess-rules): New variable.
(ffap-latex-mode): Use kpsewhich if available.
| -rw-r--r-- | lisp/ffap.el | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el index d95dad109eb..975f7269192 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el | |||
| @@ -90,7 +90,6 @@ | |||
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | ;;; Todo list: | 92 | ;;; Todo list: |
| 93 | ;; * use kpsewhich | ||
| 94 | ;; * let "/dir/file#key" jump to key (tag or regexp) in /dir/file | 93 | ;; * let "/dir/file#key" jump to key (tag or regexp) in /dir/file |
| 95 | ;; * find file of symbol if TAGS is loaded (like above) | 94 | ;; * find file of symbol if TAGS is loaded (like above) |
| 96 | ;; * break long menus into multiple panes (like imenu?) | 95 | ;; * break long menus into multiple panes (like imenu?) |
| @@ -894,6 +893,24 @@ URL, or nil. If nil, search the alist for further matches.") | |||
| 894 | "Path where `ffap-tex-mode' looks for TeX files. | 893 | "Path where `ffap-tex-mode' looks for TeX files. |
| 895 | If t, `ffap-tex-init' will initialize this when needed.") | 894 | If t, `ffap-tex-init' will initialize this when needed.") |
| 896 | 895 | ||
| 896 | (defvar ffap-latex-guess-rules '(("" . ".sty") | ||
| 897 | ("" . ".cls") | ||
| 898 | ("" . ".ltx") | ||
| 899 | ("" . ".tex") | ||
| 900 | ("" . "") ;; in some rare cases the | ||
| 901 | ;; extension is already in | ||
| 902 | ;; the buffer. | ||
| 903 | ("beamertheme" . ".sty") | ||
| 904 | ("beamercolortheme". ".sty") | ||
| 905 | ("beamerfonttheme". ".sty") | ||
| 906 | ("beamerinnertheme". ".sty") | ||
| 907 | ("beameroutertheme". ".sty") | ||
| 908 | ("" . ".ldf")) | ||
| 909 | "List of rules for guessing a filename. | ||
| 910 | Each rule is a cons (PREFIX . SUFFIX) used for guessing a | ||
| 911 | filename from the word at point by prepending PREFIX and | ||
| 912 | appending SUFFIX.") | ||
| 913 | |||
| 897 | (defun ffap-tex-init () | 914 | (defun ffap-tex-init () |
| 898 | ;; Compute ffap-tex-path if it is now t. | 915 | ;; Compute ffap-tex-path if it is now t. |
| 899 | (and (eq t ffap-tex-path) | 916 | (and (eq t ffap-tex-path) |
| @@ -917,9 +934,56 @@ If t, `ffap-tex-init' will initialize this when needed.") | |||
| 917 | (ffap-locate-file name '(".tex" "") ffap-tex-path)) | 934 | (ffap-locate-file name '(".tex" "") ffap-tex-path)) |
| 918 | 935 | ||
| 919 | (defun ffap-latex-mode (name) | 936 | (defun ffap-latex-mode (name) |
| 920 | (ffap-tex-init) | 937 | "`ffap' function suitable for latex buffers. |
| 921 | ;; only rare need for "" | 938 | This uses the program kpsewhich if available. In this case, the |
| 922 | (ffap-locate-file name '(".cls" ".sty" ".tex" "") ffap-tex-path)) | 939 | variable `ffap-latex-guess-rules' is used for building a filename |
| 940 | out of NAME." | ||
| 941 | (cond ((file-exists-p name) | ||
| 942 | name) | ||
| 943 | ((not (executable-find "kpsewhich")) | ||
| 944 | (ffap-tex-init) | ||
| 945 | (ffap-locate-file name '(".cls" ".sty" ".tex" "") ffap-tex-path)) | ||
| 946 | (t | ||
| 947 | (let ((curbuf (current-buffer)) | ||
| 948 | (guess-rules ffap-latex-guess-rules) | ||
| 949 | (preferred-suffix-rules '(("input" . ".tex") | ||
| 950 | ("include" . ".tex") | ||
| 951 | ("usepackage" . ".sty") | ||
| 952 | ("RequirePackageWithOptions" . ".sty") | ||
| 953 | ("RequirePackage" . ".sty") | ||
| 954 | ("documentclass" . ".cls") | ||
| 955 | ("documentstyle" . ".cls") | ||
| 956 | ("LoadClass" . ".cls") | ||
| 957 | ("LoadClassWithOptions" . ".cls") | ||
| 958 | ("bibliography" . ".bib") | ||
| 959 | ("addbibresource" . "")))) | ||
| 960 | ;; We now add preferred suffix in front of suffixes. | ||
| 961 | (when | ||
| 962 | ;; The condition is essentially: | ||
| 963 | ;; (assoc (TeX-current-macro) | ||
| 964 | ;; (mapcar 'car preferred-suffix-rules)) | ||
| 965 | ;; but (TeX-current-macro) can take time, so we just | ||
| 966 | ;; check if one of the `car' in preferred-suffix-rules | ||
| 967 | ;; is found before point on the current line. It | ||
| 968 | ;; should cover most cases. | ||
| 969 | (save-excursion | ||
| 970 | (re-search-backward (regexp-opt | ||
| 971 | (mapcar 'car preferred-suffix-rules)) | ||
| 972 | (point-at-bol) | ||
| 973 | t)) | ||
| 974 | (push (cons "" (cdr (assoc (match-string 0) ; i.e. "(TeX-current-macro)" | ||
| 975 | preferred-suffix-rules))) | ||
| 976 | guess-rules)) | ||
| 977 | (setq kpsewhich-args (mapcar (lambda (rule) | ||
| 978 | (concat (car rule) name (cdr rule))) | ||
| 979 | guess-rules)) | ||
| 980 | (with-temp-buffer | ||
| 981 | (let ((process-environment (buffer-local-value | ||
| 982 | 'process-environment curbuf)) | ||
| 983 | (exec-path (buffer-local-value 'exec-path curbuf))) | ||
| 984 | (apply #'call-process "kpsewhich" nil t nil kpsewhich-args)) | ||
| 985 | (when (< (point-min) (point-max)) | ||
| 986 | (buffer-substring (goto-char (point-min)) (point-at-eol)))))))) | ||
| 923 | 987 | ||
| 924 | (defun ffap-tex (name) | 988 | (defun ffap-tex (name) |
| 925 | (ffap-tex-init) | 989 | (ffap-tex-init) |