commit 28401e4c6d1c9da817bb035b1839fe75fca78acd
parent 3005a6eb92c3c50b6bd29228bb27651547550d92
Author: Tomas Hlavaty <tom@logand.com>
Date: Tue, 5 Aug 2025 00:13:08 +0200
remove ffap
Diffstat:
| M | emacs-btap.el | | | 109 | ++++++++++++++++++++++++++++++++++++------------------------------------------- |
1 file changed, 49 insertions(+), 60 deletions(-)
diff --git a/emacs-btap.el b/emacs-btap.el
@@ -4,30 +4,31 @@
;;;
;;; Browse thing at point.
;;;
-;;; Copyright (C) 2020 Tomas Hlavaty <tom at logand dot com>
+;;; Copyright (C) 2020--2025 Tomas Hlavaty <tom at logand dot com>
;;;
;;; License: GPLv3 or later
;;;
;;; Download: git clone https://logand.com/git/emacs-btap.git
;;;
-;;; Example configuration:
+;;; Configuration:
;;;
-;;; (add-to-list 'load-path "~/git/emacs-btap")
-;;; (require 'emacs-btap)
-;;; (global-set-key "\M-f" 'btap)
+;;; (add-to-list 'load-path "~/git/emacs-btap")
+;;; (require 'emacs-btap)
+;;; (global-set-key "\M-f" 'btap)
;;;
-;;; Example usage:
+;;; To see customizable variables, evaluate: (occur "defcustom")
;;;
-;;; M-x btap will browse the thing at point.
+;;; Usage:
;;;
-;;; Some variables can be customized in the btap group.
+;;; M-x btap will browse the thing at point.
;;;
-;;; To see a few examples, evaluate: (occur "example:")
+;;; Examples:
+;;;
+;;; To see a few examples, evaluate: (occur "example:")
(require 'browse-url)
-(require 'cl-lib)
-(require 'ffap)
(require 'thingatpt)
+(require 'files)
(defcustom btap-try-functions '(
;; global
@@ -35,8 +36,8 @@
btap-try-man
btap-try-url
btap-try-file
- btap-try-wild-file
btap-try-clhs
+ btap-try-emacs-bug
btap-try-sbcl-bug
;; mode specific
btap-try-cc-mode
@@ -52,73 +53,64 @@ handles the btap action."
:type '(repeat symbol)
:group 'btap)
-(defvar btap--ffap-guesser-thunk)
-(defun btap-ffap-guesser ()
- (funcall btap--ffap-guesser-thunk))
+(defun btap-url-at-point (&optional extra-uri-schemes)
+ (let ((thing-at-point-uri-schemes
+ (append extra-uri-schemes thing-at-point-uri-schemes)))
+ (thing-at-point 'url t)))
+
+(defun btap-file-at-point ()
+ (thing-at-point 'existing-filename t))
+
+(defun btap-regexp-at-point (regexp distance)
+ (let ((x (thing-at-point-looking-at regexp distance)))
+ (when x
+ (buffer-substring-no-properties (match-beginning 0) (match-end 0)))))
+
+(defun btap-symbol-at-point ()
+ (thing-at-point 'symbol t))
(defun btap-try-notmuch (&optional string)
(when (fboundp 'notmuch-show)
- (let ((x (or string (btap-ffap-guesser))))
+ (let ((x (or string (btap-url-at-point '("id:")))))
(when (and x (string-match "^id:" x))
(funcall 'notmuch-show x)
x))))
+;; example: id:87wncxxjv7.fsf@gnus.org
(defun btap-try-man (&optional string)
(when browse-url-man-function
- (let ((x (or string (btap-ffap-guesser))))
+ (let ((x (or string (btap-url-at-point '("man:")))))
(when (and x (string-match "^man:" x))
(funcall browse-url-man-function x)
x))))
;; example: man:printf
(defun btap-try-url (&optional string)
- (when ffap-url-fetcher
- (let ((x (or string (btap-ffap-guesser))))
- (when x
- (let ((url (ffap-url-p x)))
- (when url
- (let (current-prefix-arg)
- (funcall ffap-url-fetcher url)
- url)))))))
+ (let ((x (or string (btap-url-at-point))))
+ (when x
+ (browse-url x)
+ x)))
;; example: https://logand.com
(defun btap-try-cc-mode (&optional string)
(when (and (boundp 'c-buffer-is-cc-mode)
c-buffer-is-cc-mode)
- (let ((x (or string (thing-at-point 'word t))))
+ (let ((x (or string (btap-regexp-at-point (rx bow (+ (any "0-9a-zA-Z_")) eow) 30))))
(when x
;; TODO includes e.g. limits.h
(btap-try-man (concat "man:" x))))))
(defun btap-try-file (&optional string)
- (when ffap-file-finder
- (let ((x (or string (btap-ffap-guesser))))
- (when x
- (let ((url (ffap-url-p x)))
- (unless url
- (when (file-exists-p x)
- (funcall ffap-file-finder (expand-file-name x))
- x)))))))
+ (let ((x (or string (btap-file-at-point))))
+ (when x
+ (find-file (expand-file-name x))
+ x)))
;; example: ~/.emacs
;; example: ~/.emacs.d
-(defun btap-try-wild-file (&optional string)
- (when (and ffap-dired-wildcards
- find-file-wildcards
- ffap-file-finder)
- (let ((x (or string (btap-ffap-guesser))))
- (when x
- (let ((url (ffap-url-p x)))
- (unless url
- (when (and (string-match ffap-dired-wildcards x)
- ;; Check if it's find-file that supports wildcards arg
- (memq ffap-file-finder '(find-file find-alternate-file)))
- (funcall ffap-file-finder (expand-file-name x) t)
- x)))))))
-
(defun btap-try-clhs (&optional string)
(when (fboundp 'hyperspec-lookup)
- (let ((x (or string (btap-ffap-guesser))))
+ (let ((x (or string (btap-url-at-point '("clhs:")))))
(when (and x (string-match "^clhs:" x))
(funcall 'hyperspec-lookup (substring x 5))
x))))
@@ -127,13 +119,19 @@ handles the btap action."
(defun btap-try-lisp-mode (&optional string)
(when (and (fboundp 'hyperspec-lookup)
(eq major-mode 'lisp-mode))
- (let ((x (or string (thing-at-point 'word t)))) ;; TODO include - etc
+ (let ((x (or string (btap-symbol-at-point))))
(when x
(funcall 'hyperspec-lookup x)
x))))
+(defun btap-try-emacs-bug (&optional string)
+ (let ((x (or string (btap-regexp-at-point (rx bow "bug#" (+ digit) eow) 10))))
+ (when (and x (string-match "^bug#" x))
+ (btap-try-url (concat "https://debbugs.gnu.org/cgi/bugreport.cgi?bug=" (substring x 4))))))
+;; example: bug#36649
+
(defun btap-try-sbcl-bug (&optional string)
- (let ((x (or string (thing-at-point 'filename t))))
+ (let ((x (or string (btap-regexp-at-point (rx bow "lp#" (+ digit) eow) 10))))
(when (and x (string-match "^lp#" x))
(btap-try-url (concat "https://bugs.launchpad.net/bugs/" (substring x 3))))))
;; example: lp#1903901
@@ -142,19 +140,10 @@ handles the btap action."
(signal 'btap-try-missing (list "Nothing at point to browse")))
;; example: /does-not-exist
-(defun btap--memoize-thunk (thunk)
- (let (z)
- (lambda ()
- (when thunk
- (setq z (funcall thunk)
- thunk nil))
- z)))
-
(defun btap ()
"Browse thing at point. See also the variable `btap-try-functions'."
(interactive)
(let (z
- (btap--ffap-guesser-thunk (btap--memoize-thunk 'ffap-guesser))
(x btap-try-functions))
(while (and x (not (setq z (funcall (pop x))))))
z))