annotate lisp/hyperbole/hypb.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 4103f0995bd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: hypb.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Miscellaneous Hyperbole support features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: extensions, hypermedia
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ORG: Brown U.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 6-Oct-91 at 03:42:38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 30-Oct-95 at 21:23:19 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1991-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (mapcar 'require '(hversion hact))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defconst hypb:help-buf-suffix " Hypb Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 "Suffix attached to all native Hyperbole help buffer names.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun hypb:call-process-p (program infile &optional predicate &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Calls an external PROGRAM with INFILE for input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 If PREDICATE is given, it is evaluated in a buffer with the PROGRAM's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 output and the result returned. If PREDICATE is nil, returns t iff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 program has no output or just a 0-valued output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Rest of ARGS are passed as arguments to PROGRAM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let ((buf (get-buffer-create "*test-output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (set-buffer buf) (setq buffer-read-only nil) (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (apply 'call-process program infile buf nil args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (eval predicate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (or (= (point-max) 1) ;; No output, consider cmd a success.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (and (< (point-max) 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (string= (buffer-substring 1 2) "0")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun hypb:chmod (op octal-permissions file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Uses OP and OCTAL-PERMISSIONS integer to set FILE permissions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 OP may be +, -, xor, or default =."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (let ((func (cond ((eq op '+) (function logior))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ((eq op '-) (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (lambda (p1 p2) (logand (lognot p1) p2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ((eq op 'xor) (function logxor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (t (function (lambda (p1 p2) p1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (set-file-modes file (funcall func (hypb:oct-to-int octal-permissions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (file-modes file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defun hypb:cmd-key-string (cmd-sym &optional keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "Returns a single pretty printed key sequence string bound to CMD-SYM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 Global keymap is used unless optional KEYMAP is given."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (if (and cmd-sym (symbolp cmd-sym) (fboundp cmd-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (let* ((get-keys (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (lambda (cmd-sym keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (key-description (where-is-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 cmd-sym keymap 'first)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (keys (funcall get-keys cmd-sym keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (concat "{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if (string= keys "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (concat (funcall get-keys 'execute-extended-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 " " (symbol-name cmd-sym) " RTN")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "}"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (error "(hypb:cmd-key-string): Invalid cmd-sym arg: %s." cmd-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun hypb:configuration (&optional out-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Insert Emacs configuration information at the end of optional OUT-BUF or the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (and out-buf (set-buffer out-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (delete-blank-lines) (delete-blank-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (insert (format "I use:\tEditor: %s\n\tHyperbole: %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (boundp 'epoch::version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 epoch::version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 " of .+" (emacs-version) "" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 hyperb:version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (if (and (boundp 'system-configuration) (stringp system-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (insert (format "\tSys Type: %s\n" system-configuration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (insert (format "\tOS Type: %s\n\tWindow Sys: %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 system-type (or window-system hyperb:window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "None")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (and (boundp 'hmail:reader) hmail:reader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (insert (format "\tMailer: %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (cond ((eq hmail:reader 'rmail-mode) "RMAIL")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ((eq hmail:reader 'vm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (concat "VM " vm-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ((and (eq hmail:reader 'mh-show-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (string-match "v ?\\([0-9]+.[0-9]+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 mh-e-RCS-id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (concat "MH-e "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (substring mh-e-RCS-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ((eq hmail:reader 'pm-fdr-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (concat "PIEmail " pm-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (and (boundp 'hnews:reader) (boundp 'gnus-version) hnews:reader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (insert (format "\tNews Rdr: %s\n" gnus-version)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (and (boundp 'br-version) (stringp br-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (insert (format "\tOO-Browser: %s\n" br-version)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (untabify start (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (if (fboundp 'copy-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (fset 'hypb:copy-sublists 'copy-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; This function is derived from a copylefted function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; Define hypb:copy-sublists if not a builtin. This version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; is a Lisp translation of the C version in Lemacs 19.8.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; Available for use and distribution under the GPL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun hypb:copy-sublists (obj &optional vector-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "Return a copy of a list and substructures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 The argument is copied, and any lists contained within it are copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 recursively. Circularities and shared substructures are not preserved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 Second arg VECP causes vectors to be copied, too. Strings are not copied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (cond ((consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (let (rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq obj (copy-sequence obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 rest obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (while (consp rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (let ((elt (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if quit-flag (top-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (or (consp elt) (vectorp elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setcar rest (hypb:copy-sublists elt vector-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (if (vectorp (cdr rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (setcdr rest (hypb:copy-sublists (cdr rest) vector-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq rest (cdr rest))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ((and (vectorp obj) obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (let ((i (length obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (j 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (setq obj (copy-sequence obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (while (< j i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (setq elt (aref obj j))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if quit-flag (top-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if (or (consp elt) (vectorp elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (aset obj j (hypb:copy-sublists elt vector-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq j (1+ j))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defun hypb:debug ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "Loads Hyperbole hbut.el source file and sets debugging traceback flag."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (or (featurep 'hinit) (load "hsite"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (or (and (featurep 'hbut)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (let ((func (hypb:indirect-function 'ebut:create)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (not (or (hypb:v19-byte-code-p func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (eq 'byte-code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (car (car (nthcdr 3 (hypb:indirect-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 'ebut:create)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (load "hbut.el"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (setq debug-on-error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defun hypb:domain-name ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "Returns current Internet domain name with '@' prepended or nil if none."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (let* ((dname-cmd (or (file-exists-p "/usr/bin/domainname")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (file-exists-p "/bin/domainname")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (dname (or (getenv "DOMAINNAME")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if dname-cmd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (hypb:call-process-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "domainname" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 '(substring (buffer-string) 0 -1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (if (or (and dname (string-match "\\." dname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (let* ((src "/etc/resolv.conf")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (src-buf-exists-p (get-file-buffer src)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (and (file-exists-p src) (file-readable-p src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (set-buffer (find-file-noselect src))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (if (re-search-forward "^domain[ \t]+\\([^ \t\n]+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (setq dname (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (or src-buf-exists-p (kill-buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 dname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (concat "@" dname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (defun hypb:error (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 "Signals an error typically to be caught by 'hui:menu'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (let ((msg (apply 'format args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (put 'error 'error-message msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (error msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (defun hypb:functionp (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 "Returns t if OBJ is a function, nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ((symbolp obj) (fboundp obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ((subrp obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ((hypb:v19-byte-code-p obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ((consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (defun hypb:function-copy (func-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 "Copies FUNC-SYMBOL's body for overloading. Returns copy of body."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (if (fboundp func-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (let ((func (hypb:indirect-function func-symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (cond ((listp func) (copy-sequence func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ((subrp func) (error "(hypb:function-copy): `%s' is a primitive; can't copy body."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 func-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ((and (hypb:v19-byte-code-p func) (fboundp 'make-byte-code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (let ((new-code (append func nil))) ; turn it into a list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (apply 'make-byte-code new-code)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (t (error "(hypb:function-copy): Can't copy function body: %s" func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (error "(hypb:function-copy): `%s' symbol is not bound to a function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 func-symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (defun hypb:function-overload (func-sym prepend &rest new-forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 "Redefine function named FUNC-SYM by either PREPENDing (or appending if nil) rest of quoted NEW-FORMS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (let ((old-func-sym (intern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (concat "*hypb-old-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (symbol-name func-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 "*"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (or (fboundp old-func-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (fset old-func-sym (hypb:function-copy func-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (let* ((old-func (hypb:indirect-function old-func-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (old-param-list (action:params old-func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (param-list (action:param-list old-func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (old-func-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (list (if (memq '&rest old-param-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; Have to account for extra list wrapper from &rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (cons 'apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (cons (list 'quote old-func-sym) param-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (cons old-func-sym param-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (eval (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (list 'defun func-sym old-param-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (delq nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (documentation old-func-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (action:commandp old-func-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (if prepend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (append new-forms old-func-call)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (append old-func-call new-forms)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defun hypb:function-symbol-replace (func-sym sym-to-replace replace-with-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "Replaces in body of FUNC-SYM SYM-TO-REPLACE with REPLACE-WITH-SYM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 All occurrences within lists are replaced. Returns body of modified FUNC-SYM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (let ((body (hypb:indirect-function func-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (arg-vector) (arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if (listp body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; assume V18 byte compiler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq arg-vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (car (delq nil (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (and (listp elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (vectorp (setq arg-vector (nth 2 elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 arg-vector)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; assume V19 byte compiler (eq (compiled-function-p body) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq arg (aref body 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 arg-vector (if (vectorp arg) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if arg-vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; Code is byte-compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (let ((i (1- (length arg-vector))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (setq arg nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (while (and (not arg) (>= i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if (eq (setq arg (aref arg-vector i)) sym-to-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (aset arg-vector i replace-with-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq arg nil i (1- i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; Code is not byte-compiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; Only replaces occurrence of symbol as an element of a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (hypb:map-sublists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (lambda (atom list) (if (eq atom sym-to-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (let ((again t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (while (and again list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (if (eq (car list) atom)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (progn (setcar list replace-with-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq again nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq list (cdr list))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defun hypb:help-buf-name (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "Returns a Hyperbole help buffer name for current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 With optional PREFIX string, uses it rather than buffer name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (let ((bn (or prefix (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (if (string-match " Hypb " bn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (buffer-name (generate-new-buffer bn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (concat "*" bn hypb:help-buf-suffix))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (defun hypb:indirect-function (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "Return the function at the end of OBJ's function chain.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Resolves autoloadable function symbols properly."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (let ((func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (if (fboundp 'indirect-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (indirect-function obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (while (symbolp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq obj (symbol-function obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ;; Handle functions with autoload bodies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (if (and (symbolp obj) (listp func) (eq (car func) 'autoload))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (let ((load-file (car (cdr func))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (load load-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; Prevent infinite recursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (if (equal func (symbol-function obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (error "(hypb:indirect-function): Autoload of '%s' failed" obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (hypb:indirect-function obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (defun hypb:insert-region (buffer start end invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 "Insert into BUFFER the contents of a region from START to END in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 INVISIBLE-FLAG, if non-nil, means invisible text in an outline region is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 copied, otherwise, it is omitted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (let ((from-koutline (eq major-mode 'kotl-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (append-to-buffer buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (let ((first (- (point) (- end start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (last (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; Remove from buffer any copied text that was hidden if invisible-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 ;; is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (if invisible-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; Show all hidden text within the copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (subst-char-in-region first last ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; Remove hidden text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (goto-char first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (while (search-forward "\r" last t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (delete-region (1- (point)) (progn (end-of-line) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; If region came from a koutline, remove any characters with an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; invisible property which separate cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (if from-koutline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (kproperty:map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (function (lambda (prop) (delete-char 1))) 'invisible t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if (or hyperb:lemacs-p hyperb:emacs19-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (fset 'hypb:mark 'mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defun hypb:mark (inactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 "Return this buffer's mark value as integer, or nil if no mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 INACTIVE-P non-nil means return value of mark even if region is not active
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 under Emacs version 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 If you are using this in an editing command, you are most likely making
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 a mistake; see the documentation of `set-mark'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (if hyperb:lemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (fset 'hypb:mark-marker 'mark-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (defun hypb:mark-marker (inactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 "Return this buffer's mark as a marker object, or nil if no mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 INACTIVE-P is unused, it is for compatibility with Lucid Emacs'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 version of mark-marker."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (mark-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (defun hypb:map-sublists (func list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 "Applies FUNC to every atom found at any level of LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 FUNC must take two arguments, an atom and a list in which the atom is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 Returns values from applications of FUNC as a list with the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 structure as LIST. FUNC is therefore normally used just for its side-effects."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (lambda (elt) (if (atom elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (funcall func elt list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (hypb:map-sublists func elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defun hypb:map-vector (func object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Returns list of results of application of FUNC to each element of OBJECT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 OBJECT should be a vector or byte-code object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (if (not (or (vectorp object) (hypb:v19-byte-code-p object)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (error "(hypb:map-vector): Second argument must be a vector or byte-code object."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (let ((end (length object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (while (< i end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq result (cons (funcall func (aref object i)) result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (nreverse result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (defun hypb:mouse-help-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Return the full path to the Hyperbole mouse key help file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (let* ((hypb-man (expand-file-name "man/" hyperb:dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (help-file (expand-file-name "hypb-mouse.txt" hypb-man)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (if (or (file-exists-p help-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (setq help-file (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 "hypb-mouse.txt" data-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 help-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (error "(hypb:mouse-help-file): Non-existent file: \"%s\"" help-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (if (or hyperb:lemacs-p hyperb:emacs19-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (fset 'hypb:push-mark 'push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun hypb:push-mark (&optional location nomsg activate-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 If the last global mark pushed was not in the current buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 also push LOCATION on the global mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Display `Mark set' unless the optional second arg NOMSG is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 Optional third arg ACTIVATE-REGION is ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 Novice Emacs Lisp programmers often try to use the mark for the wrong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 purposes. See the documentation of `set-mark' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (push-mark location nomsg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (defun hypb:replace-match-string (regexp str newtext &optional literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 "Replaces all matches for REGEXP in STR with NEWTEXT string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Optional LITERAL non-nil means do a literal replacement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 Otherwise treat \\ in NEWTEXT string as special:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 \\& means substitute original matched text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 \\N means substitute match for \(...\) number N,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 \\\\ means insert one \\.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 NEWTEXT may instead be a function of one argument, the string to replace in,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 that returns a replacement string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (not (stringp str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (error "(hypb:replace-match-string): 2nd arg must be a string: %s" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if (or (stringp newtext) (hypb:functionp newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (error "(hypb:replace-match-string): 3rd arg must be a string or function: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (let ((rtn-str "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 match prev-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (while (setq match (string-match regexp str start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (setq prev-start start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 start (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 rtn-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 rtn-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (substring str prev-start match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (cond ((hypb:functionp newtext) (funcall newtext str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (literal newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (t (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (if special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (setq special nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (cond ((eq c ?\\) "\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ((eq c ?&)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (substring str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ((and (>= c ?0) (<= c ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (if (> c (+ ?0 (length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (match-data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; Invalid match num
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (error "(hypb:replace-match-string) Invalid match num: %c" c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (setq c (- c ?0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (substring str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (match-beginning c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (match-end c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (t (char-to-string c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (if (eq c ?\\) (progn (setq special t) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (char-to-string c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 newtext ""))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (concat rtn-str (substring str start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (defun hypb:supercite-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 "Returns non-nil iff the Emacs add-on supercite package is in use."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (let (hook-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (if (memq t (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (lambda (hook-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (and (boundp hook-var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (progn (setq hook-val (symbol-value hook-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (cond ((listp hook-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (if (memq 'sc-cite-original hook-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ((eq hook-val 'sc-cite-original)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 '(mail-citation-hook mail-yank-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;;; Next function is copied from a copylefted function:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;;; Copyright (C) 1987, 1988 Kyle E. Jones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if (or hyperb:lemacs-p hyperb:emacs19-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (defun hypb:window-list-all-frames (&optional mini)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 "Returns a list of Lisp window objects for all Emacs windows in all frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 Optional first arg MINI t means include the minibuffer window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 in the list, even if it is not active. If MINI is neither t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 nor nil it means to not count the minibuffer window even if it is active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (let* ((first-window (next-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (previous-window (selected-window) nil t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 mini t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (windows (cons first-window nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (current-cons windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (w (next-window first-window mini t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (while (not (eq w first-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (setq current-cons (setcdr current-cons (cons w nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (setq w (next-window w mini t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 windows)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ;;; Next function is copied from a copylefted function:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;;; Copyright (C) 1987, 1988 Kyle E. Jones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (defun hypb:window-list (&optional mini)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 "Returns a list of Lisp window objects for all Emacs windows in selected frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 Optional first arg MINI t means include the minibuffer window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 in the list, even if it is not active. If MINI is neither t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 nor nil it means to not count the minibuffer window even if it is active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (let* ((first-window (next-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (previous-window (selected-window)) mini))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (windows (cons first-window nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (current-cons windows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (w (next-window first-window mini)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (while (not (eq w first-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (setq current-cons (setcdr current-cons (cons w nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (setq w (next-window w mini)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 windows))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (defun hypb:v19-byte-code-p (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 "Return non-nil iff OBJ is an Emacs V19 byte compiled object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (or (and (fboundp 'compiled-function-p) (compiled-function-p obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (and (fboundp 'byte-code-function-p) (byte-code-function-p obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (defun hypb:oct-to-int (oct-num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 "Returns octal integer OCTAL-NUM converted to a decimal integer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (let ((oct-str (int-to-string oct-num))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (dec-num 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (and (string-match "[^0-7]" oct-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (error (format "(hypb:oct-to-int): Bad octal number: %s" oct-str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (mapconcat (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (lambda (o)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (setq dec-num (+ (* dec-num 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (if (and (>= o ?0) (<= o ?7))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (- o ?0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 oct-str "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 dec-num))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (provide 'hypb)