File: acl2-doc-open-url.el

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (60 lines) | stat: -rw-r--r-- 2,560 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
; ACL2 Version 8.6 -- A Computational Logic for Applicative Common Lisp
; Copyright (C) 2024, Matt Kaufmann
; License: A 3-clause BSD license.  See the LICENSE file distributed with ACL2.

; This is an extension to emacs/acl2-doc.el that defines the key, U,
; to bring up a URL, or a local file "res/...", in a web browser.  It
; should only be loaded after emacs/acl2-doc.el is loaded.

; Of course, this won't work if you are running acl2-doc from inside
; an Emacs that is not window-based -- for example, if your Emacs is
; running from within the "screen" program.

; At some point this file might be incorporated into acl2-doc.el.
; Perhaps the "g" command will be enhanced at that point, so that if
; one is looking at a word that seems to represent a URL or a local
; "res/..." name, then an error message will suggest using "U"
; instead.  Or perhaps "g" will simply invoke "U" in that case.

; Requirements:

; You'll need Emacs variable browse-url-browser-function to be set to
; browse-url-PROGRAM, where PROGRAM brings up a browser.  For example,
; you could put the form (setq browse-url-browser-function (quote
; browse-url-firefox)) in your ~/.emacs file, which will set
; browse-url-browser-function to the value, browse-url-firefox.  But
; then the command, firefox, needs to be on your path.  One way to
; accomplish this is to arrange for Emacs variable exec-path to
; include, say, "~/bin", in the list value of Emacs variable exec-path
; -- e.g., by including into your .emacs file the form
;   (setq exec-path
;         (append (butlast exec-path 1) '("~/bin") (last exec-path)))
; -- and then have something like the following in ~/bin/firefox (this
; has worked on a Mac; a different command, perhaps just a call of
; "firefox" [rather than "open"], may work on Linux):

; #!/usr/bin/env bash
; open -a 'firefox' "$@"

(defun manual-dir ()
  (concat *acl2-doc-directory* "../../doc/manual"))

(defun acl2-doc-open-url ()
  (interactive)
  (let ((topic (acl2-doc-topic-at-point)))
    (if (not topic)
	(error "No topic at point."))
    (let* ((topic (downcase (symbol-name topic)))
	   (len (length topic)))
      (if (equal (aref topic (1- len)) ?})
	  (setq topic (substring topic 0 (1- len))))
      (let ((url (if (and (> len 4)
			  (equal (substring topic 0 4) "res/"))
		     (concat "file://" (manual-dir) "/" topic)
		   (if (and (> len 4)
			    (equal (substring topic 0 4) "http"))
		       topic
		     (error "No available topic at point.")))))
	(browse-url url)))))

(define-key acl2-doc-mode-map "U" 'acl2-doc-open-url)