aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-05-05 23:40:22 +0000
committerRichard M. Stallman1997-05-05 23:40:22 +0000
commitc9ae98693754d82271ad7e6ba623284e91f6ed6f (patch)
treeb303bca83a000105048566b5495785d476e4f481
parentaf4d27fbe6f6afcc680f9859836efead2279d69c (diff)
downloademacs-c9ae98693754d82271ad7e6ba623284e91f6ed6f.tar.gz
emacs-c9ae98693754d82271ad7e6ba623284e91f6ed6f.zip
(ffap-alist): Delete `math-mode'.
Move all defvars and defuns out of this, to top level. Use a constant list as the initial value. (ffap-soft-value): Rewrite as a macro. And now it is used only at run time, not at load time. (ffap-ftp-default-user): Use just "anonymous" as default value. (ffap-what-domain): Don't set mail-extr-all-top-level-domains here. (ffap-newsgroup-regexp, ffap-newsgroup-heads): Move up past first use. (ffap-string-at-point-region): Likewise.
-rw-r--r--lisp/ffap.el297
1 files changed, 151 insertions, 146 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el
index bb4c4612c83..647e52bb5fb 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -107,12 +107,14 @@
107 107
108 108
109;; This function is used inside defvars: 109;; This function is used inside defvars:
110(defun ffap-soft-value (name &optional default) 110(defmacro ffap-soft-value (name &optional default)
111 "Return value of symbol with NAME, if it is interned. 111 "Return value of symbol with NAME, if it is interned.
112Otherwise return nil (or the optional DEFAULT value)." 112Otherwise return nil (or the optional DEFAULT value)."
113 ;; Bug: (ffap-soft-value "nil" 5) --> 5 113 ;; Bug: (ffap-soft-value "nil" 5) --> 5
114 (let ((sym (intern-soft name))) 114 (let ((sym (intern-soft name)))
115 (if (and sym (boundp sym)) (symbol-value sym) default))) 115 (if (and sym (boundp sym))
116 sym
117 `(quote ,default))))
116 118
117 119
118(defcustom ffap-ftp-regexp 120(defcustom ffap-ftp-regexp
@@ -142,10 +144,7 @@ This is ignored if `ffap-ftp-regexp' is nil."
142 :group 'ffap) 144 :group 'ffap)
143 145
144(defcustom ffap-ftp-default-user 146(defcustom ffap-ftp-default-user
145 (if (or (equal (ffap-soft-value "ange-ftp-default-user") "anonymous") 147 "anonymous"
146 (equal (ffap-soft-value "efs-default-user") "anonymous"))
147 nil
148 "anonymous")
149 "*User name in ftp paths generated by `ffap-host-to-path'. 148 "*User name in ftp paths generated by `ffap-host-to-path'.
150nil to rely on `efs-default-user' or `ange-ftp-default-user'." 149nil to rely on `efs-default-user' or `ange-ftp-default-user'."
151 :type '(choice (const :tag "Default" nil) 150 :type '(choice (const :tag "Default" nil)
@@ -252,7 +251,12 @@ For a fancier alternative, get ffap-url.el."
252 :type 'regexp 251 :type 'regexp
253 :group 'ffap) 252 :group 'ffap)
254 253
255(defvar ffap-next-guess nil "Last value returned by `ffap-next-guess'.") 254(defvar ffap-next-guess nil
255 "Last value returned by `ffap-next-guess'.")
256
257(defvar ffap-string-at-point-region '(1 1)
258 "List (BEG END), last region returned by `ffap-string-at-point'.")
259
256(defun ffap-next-guess (&optional back lim) 260(defun ffap-next-guess (&optional back lim)
257 "Move point to next file or URL, and return it as a string. 261 "Move point to next file or URL, and return it as a string.
258If nothing is found, leave point at limit and return nil. 262If nothing is found, leave point at limit and return nil.
@@ -360,8 +364,6 @@ What `ffap-machine-p' does with hostnames that have an unknown domain
360(defun ffap-what-domain (domain) 364(defun ffap-what-domain (domain)
361 ;; Like what-domain in mail-extr.el, returns string or nil. 365 ;; Like what-domain in mail-extr.el, returns string or nil.
362 (require 'mail-extr) 366 (require 'mail-extr)
363 (defvar mail-extr-all-top-level-domains
364 (ffap-soft-value "all-top-level-domains" obarray)) ; XEmacs, old Emacs
365 (get (intern-soft (downcase domain) mail-extr-all-top-level-domains) 367 (get (intern-soft (downcase domain) mail-extr-all-top-level-domains)
366 'domain-name)) 368 'domain-name))
367 369
@@ -477,6 +479,12 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
477 (ffap-ftp-regexp (ffap-host-to-path mach)) 479 (ffap-ftp-regexp (ffap-host-to-path mach))
478 )) 480 ))
479 481
482(defvar ffap-newsgroup-regexp "^[a-z]+\\.[-+a-z_0-9.]+$"
483 "Strings not matching this fail `ffap-newsgroup-p'.")
484(defvar ffap-newsgroup-heads ; entirely inadequate
485 '("alt" "comp" "gnu" "misc" "news" "sci" "soc" "talk")
486 "Used by `ffap-newsgroup-p' if gnus is not running.")
487
480(defun ffap-newsgroup-p (string) 488(defun ffap-newsgroup-p (string)
481 "Return STRING if it looks like a newsgroup name, else nil." 489 "Return STRING if it looks like a newsgroup name, else nil."
482 (and 490 (and
@@ -502,11 +510,6 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"."
502 (setq ret string)))) 510 (setq ret string))))
503 ;; Is there ever a need to modify string as a newsgroup name? 511 ;; Is there ever a need to modify string as a newsgroup name?
504 ret))) 512 ret)))
505(defvar ffap-newsgroup-regexp "^[a-z]+\\.[-+a-z_0-9.]+$"
506 "Strings not matching this fail `ffap-newsgroup-p'.")
507(defvar ffap-newsgroup-heads ; entirely inadequate
508 '("alt" "comp" "gnu" "misc" "news" "sci" "soc" "talk")
509 "Used by `ffap-newsgroup-p' if gnus is not running.")
510 513
511(defsubst ffap-url-p (string) 514(defsubst ffap-url-p (string)
512 "If STRING looks like an url, return it (maybe improved), else nil." 515 "If STRING looks like an url, return it (maybe improved), else nil."
@@ -603,135 +606,27 @@ Uses `path-separator' to separate the path into directories."
603 606
604(defvar ffap-alist 607(defvar ffap-alist
605 ;; A big mess! Parts are probably useless. 608 ;; A big mess! Parts are probably useless.
606 (list 609 '(
607 (cons "\\.info\\'" 610 ("\\.info\\'" . ffap-info)
608 (defun ffap-info (name) 611 ;; Since so many info files do not have .info extension, also do this:
609 (locate-library 612 ("\\`info/" . ffap-info-2)
610 name '("" ".info") 613 ("\\`[-a-z]+\\'" . ffap-info-3)
611 (or (ffap-soft-value "Info-directory-list") 614 ("\\.elc?\\'" . ffap-el)
612 (ffap-soft-value "Info-default-directory-list") 615 (emacs-lisp-mode . ffap-el-mode)
613 ;; v18: 616 (finder-mode . ffap-el-mode) ; v19: {C-h p}
614 (list (ffap-soft-value "Info-directory" "~/info/")))))) 617 (help-mode . ffap-el-mode) ; v19.29
615 ;; Since so many info files do not have .info extension, also do this: 618 (c++-mode . ffap-c-mode)
616 (cons "\\`info/" 619 (cc-mode . ffap-c-mode)
617 (defun ffap-info-2 (name) (ffap-info (substring name 5)))) 620 ("\\.\\([chCH]\\|cc\\|hh\\)\\'" . ffap-c-mode)
618 (cons "\\`[-a-z]+\\'" 621 (tex-mode . ffap-tex-mode)
619 ;; This ignores the node! "(emacs)Top" same as "(emacs)Intro" 622 (latex-mode . ffap-latex-mode)
620 (defun ffap-info-3 (name) 623 ("\\.\\(tex\\|sty\\|doc\\|cls\\)\\'" . ffap-tex)
621 (and (equal (ffap-string-around) "()") (ffap-info name)))) 624 ("\\.bib\\'" . ffap-bib)
622 (cons "\\.elc?\\'" 625 ("\\`\\." . ffap-home)
623 (defun ffap-el (name) (locate-library name t))) 626 ("\\`~/" . ffap-lcd)
624 (cons 'emacs-lisp-mode 627 ("^[Rr][Ff][Cc][- #]?\\([0-9]+\\)" ; no $
625 (defun ffap-el-mode (name) 628 . ffap-rfc)
626 ;; We do not bother with "" here, since it was considered above. 629 ("\\`[^/]*\\'" . ffap-dired))
627 ;; Also ignore "elc", for speed (who else reads elc files?)
628 (and (not (string-match "\\.el\\'" name))
629 (locate-library name '(".el")))))
630 '(finder-mode . ffap-el-mode) ; v19: {C-h p}
631 '(help-mode . ffap-el-mode) ; v19.29
632 (cons 'c-mode
633 (progn
634 ;; Need better defaults here!
635 (defvar ffap-c-path '("/usr/include" "/usr/local/include"))
636 (defun ffap-c-mode (name)
637 (locate-library name t ffap-c-path))))
638 '(c++-mode . ffap-c-mode)
639 '(cc-mode . ffap-c-mode)
640 '("\\.\\([chCH]\\|cc\\|hh\\)\\'" . ffap-c-mode)
641 (cons 'tex-mode
642 ;; Complicated because auctex may not be loaded yet.
643 (progn
644 (defvar ffap-tex-path
645 t ; delayed initialization
646 "Path where `ffap-tex-mode' looks for tex files.
647If t, `ffap-tex-init' will initialize this when needed.")
648 (defun ffap-tex-init nil
649 ;; Compute ffap-tex-path if it is now t.
650 (and (eq t ffap-tex-path)
651 (message "Initializing ffap-tex-path ...")
652 (setq ffap-tex-path
653 (ffap-reduce-path
654 (append
655 (list ".")
656 (ffap-list-env "TEXINPUTS")
657 ;; (ffap-list-env "BIBINPUTS")
658 (ffap-add-subdirs
659 (ffap-list-env "TEXINPUTS_SUBDIR"
660 (ffap-soft-value
661 "TeX-macro-global"
662 '("/usr/local/lib/tex/macros"
663 "/usr/local/lib/tex/inputs")
664 ))))))))
665 (defun ffap-tex-mode (name)
666 (ffap-tex-init)
667 (locate-library name '(".tex" "") ffap-tex-path))))
668 (cons 'latex-mode
669 (defun ffap-latex-mode (name)
670 (ffap-tex-init)
671 ;; Any real need for "" here?
672 (locate-library name '(".cls" ".sty" ".tex" "")
673 ffap-tex-path)))
674 (cons "\\.\\(tex\\|sty\\|doc\\|cls\\)\\'"
675 (defun ffap-tex (name)
676 (ffap-tex-init)
677 (locate-library name t ffap-tex-path)))
678 (cons "\\.bib\\'"
679 (defun ffap-bib (name)
680 (locate-library
681 name t
682 (ffap-list-env "BIBINPUTS" '("/usr/local/lib/tex/macros/bib")))))
683 (cons 'math-mode
684 (defun ffap-math-mode (name)
685 (while (string-match "`" name)
686 (setq name (concat (substring name 0 (match-beginning 0))
687 "/"
688 (substring name (match-end 0)))))
689 (locate-library
690 name '(".m" "") (ffap-soft-value "Mathematica-search-path"))))
691 (cons "\\`\\." (defun ffap-home (name) (locate-library name t '("~"))))
692 (cons "\\`~/"
693 ;; Maybe a "Lisp Code Directory" reference:
694 (defun ffap-lcd (name)
695 (and
696 (or
697 ;; lisp-dir-apropos output buffer:
698 (string-match "Lisp Code Dir" (buffer-name))
699 ;; Inside an LCD entry like |~/misc/ffap.el.Z|,
700 ;; or maybe the holy LCD-Datafile itself:
701 (member (ffap-string-around) '("||" "|\n")))
702 (concat
703 ;; lispdir.el may not be loaded yet:
704 (ffap-host-to-path
705 (ffap-soft-value "elisp-archive-host"
706 "archive.cis.ohio-state.edu"))
707 (file-name-as-directory
708 (ffap-soft-value "elisp-archive-directory"
709 "/pub/gnu/emacs/elisp-archive/"))
710 (substring name 2)))))
711 (cons "^[Rr][Ff][Cc][- #]?\\([0-9]+\\)" ; no $
712 (progn
713 (defvar ffap-rfc-path
714 (concat (ffap-host-to-path "ds.internic.net") "/rfc/rfc%s.txt"))
715 (defun ffap-rfc (name)
716 (format ffap-rfc-path
717 (substring name (match-beginning 1) (match-end 1))))))
718 (cons "\\`[^/]*\\'"
719 (defun ffap-dired (name)
720 (let ((pt (point)) dir try)
721 (save-excursion
722 (and (progn
723 (beginning-of-line)
724 (looking-at " *[-d]r[-w][-x][-r][-w][-x][-r][-w][-x] "))
725 (re-search-backward "^ *$" nil t)
726 (re-search-forward "^ *\\([^ \t\n:]*\\):\n *total " pt t)
727 (file-exists-p
728 (setq try
729 (expand-file-name
730 name
731 (buffer-substring
732 (match-beginning 1) (match-end 1)))))
733 try)))))
734 )
735 "Alist of \(KEY . FUNCTION\) pairs parsed by `ffap-file-at-point'. 630 "Alist of \(KEY . FUNCTION\) pairs parsed by `ffap-file-at-point'.
736If string NAME at point (maybe \"\") is not a file or url, these pairs 631If string NAME at point (maybe \"\") is not a file or url, these pairs
737specify actions to try creating such a string. A pair matches if either 632specify actions to try creating such a string. A pair matches if either
@@ -741,7 +636,120 @@ On a match, \(FUNCTION NAME\) is called and should return a file, an
741url, or nil. If nil, search the alist for further matches.") 636url, or nil. If nil, search the alist for further matches.")
742 637
743(put 'ffap-alist 'risky-local-variable t) 638(put 'ffap-alist 'risky-local-variable t)
639
640(defun ffap-home (name) (locate-library name t '("~")))
641
642(defun ffap-info (name)
643 (locate-library
644 name '("" ".info")
645 (or (ffap-soft-value "Info-directory-list")
646 (ffap-soft-value "Info-default-directory-list")
647 ;; v18:
648 (list (ffap-soft-value "Info-directory" "~/info/")))))
649
650(defun ffap-info-2 (name) (ffap-info (substring name 5)))
651
652;; This ignores the node! "(emacs)Top" same as "(emacs)Intro"
653(defun ffap-info-3 (name)
654 (and (equal (ffap-string-around) "()") (ffap-info name)))
655
656(defun ffap-el (name) (locate-library name t))
657
658;; Need better defaults here!
659(defvar ffap-c-path '("/usr/include" "/usr/local/include"))
660(defun ffap-c-mode (name)
661 (locate-library name t ffap-c-path))
662
663(defun ffap-el-mode (name)
664 ;; We do not bother with "" here, since it was considered above.
665 ;; Also ignore "elc", for speed (who else reads elc files?)
666 (and (not (string-match "\\.el\\'" name))
667 (locate-library name '(".el"))))
668
669;; Complicated because auctex may not be loaded yet.
670(defvar ffap-tex-path
671 t ; delayed initialization
672 "Path where `ffap-tex-mode' looks for tex files.
673If t, `ffap-tex-init' will initialize this when needed.")
744 674
675(defun ffap-tex-init nil
676 ;; Compute ffap-tex-path if it is now t.
677 (and (eq t ffap-tex-path)
678 (message "Initializing ffap-tex-path ...")
679 (setq ffap-tex-path
680 (ffap-reduce-path
681 (append
682 (list ".")
683 (ffap-list-env "TEXINPUTS")
684 ;; (ffap-list-env "BIBINPUTS")
685 (ffap-add-subdirs
686 (ffap-list-env "TEXINPUTS_SUBDIR"
687 (ffap-soft-value
688 "TeX-macro-global"
689 '("/usr/local/lib/tex/macros"
690 "/usr/local/lib/tex/inputs")
691 ))))))))
692
693(defun ffap-tex-mode (name)
694 (ffap-tex-init)
695 (locate-library name '(".tex" "") ffap-tex-path))
696
697(defun ffap-latex-mode (name)
698 (ffap-tex-init)
699 ;; Any real need for "" here?
700 (locate-library name '(".cls" ".sty" ".tex" "")
701 ffap-tex-path))
702
703(defun ffap-tex (name)
704 (ffap-tex-init)
705 (locate-library name t ffap-tex-path))
706
707(defun ffap-bib (name)
708 (locate-library
709 name t
710 (ffap-list-env "BIBINPUTS" '("/usr/local/lib/tex/macros/bib"))))
711
712(defun ffap-dired (name)
713 (let ((pt (point)) dir try)
714 (save-excursion
715 (and (progn
716 (beginning-of-line)
717 (looking-at " *[-d]r[-w][-x][-r][-w][-x][-r][-w][-x] "))
718 (re-search-backward "^ *$" nil t)
719 (re-search-forward "^ *\\([^ \t\n:]*\\):\n *total " pt t)
720 (file-exists-p
721 (setq try
722 (expand-file-name
723 name
724 (buffer-substring
725 (match-beginning 1) (match-end 1)))))
726 try))))
727
728;; Maybe a "Lisp Code Directory" reference:
729(defun ffap-lcd (name)
730 (and
731 (or
732 ;; lisp-dir-apropos output buffer:
733 (string-match "Lisp Code Dir" (buffer-name))
734 ;; Inside an LCD entry like |~/misc/ffap.el.Z|,
735 ;; or maybe the holy LCD-Datafile itself:
736 (member (ffap-string-around) '("||" "|\n")))
737 (concat
738 ;; lispdir.el may not be loaded yet:
739 (ffap-host-to-path
740 (ffap-soft-value "elisp-archive-host"
741 "archive.cis.ohio-state.edu"))
742 (file-name-as-directory
743 (ffap-soft-value "elisp-archive-directory"
744 "/pub/gnu/emacs/elisp-archive/"))
745 (substring name 2))))
746
747(defvar ffap-rfc-path
748 (concat (ffap-host-to-path "ds.internic.net") "/rfc/rfc%s.txt"))
749
750(defun ffap-rfc (name)
751 (format ffap-rfc-path
752 (substring name (match-beginning 1) (match-end 1))))
745 753
746;;; At-Point Functions: 754;;; At-Point Functions:
747 755
@@ -769,9 +777,6 @@ possibly a `major-mode' or some symbol internal to ffap
7692. strip BEG chars before point from the beginning, 7772. strip BEG chars before point from the beginning,
7703. Strip END chars after point from the end.") 7783. Strip END chars after point from the end.")
771 779
772(defvar ffap-string-at-point-region '(1 1)
773 "List (BEG END), last region returned by `ffap-string-at-point'.")
774
775(defvar ffap-string-at-point nil 780(defvar ffap-string-at-point nil
776 ;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95. 781 ;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95.
777 "Last string returned by `ffap-string-at-point'.") 782 "Last string returned by `ffap-string-at-point'.")