annotate lisp/hyperbole/hargs.el @ 147:e186c2b7192d xemacs-20-2

Added tag r20-2p1 for changeset 2af401a6ecca
author cvs
date Mon, 13 Aug 2007 09:34:48 +0200
parents 376386a54a3c
children
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: hargs.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Obtains user input through Emacs for Hyperbole
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: 31-Oct-91 at 23:17:35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 11-Sep-95 at 16:34:32 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 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; This module should be used for any interactive prompting and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; argument reading that Hyperbole does through Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; 'hargs:iform-read' provides a complete Lisp-based replacement for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; interactive argument reading (most of what 'call-interactively' does).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; It also supports prompting for new argument values with defaults drawn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; from current button arguments. A few extensions to interactive argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; types are also provided, see 'hargs:iforms-extensions' for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; Other required Elisp libraries
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 (require 'hpath)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (require 'set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvar hargs:reading-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "t only when Hyperbole is prompting user for input, else nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defun hargs:actype-get (actype &optional modifying)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "Interactively gets and returns list of arguments for ACTYPE's parameters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 Current button is being modified when MODIFYING is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (hargs:action-get (actype:action actype) modifying))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defun hargs:at-p (&optional no-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Returns thing at point, if of hargs:reading-p type, or default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 If optional argument NO-DEFAULT is non-nil, nil is returned instead of any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 default values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Caller should have checked whether an argument is presently being read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 and set 'hargs:reading-p' to an appropriate argument type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Handles all of the interactive argument types that 'hargs:iform-read' does."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (cond ((and (eq hargs:reading-p 'kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (eq major-mode 'kotl-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (not (looking-at "^$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ((and (eq hargs:reading-p 'klink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (not (looking-at "^$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (if (eq major-mode 'kotl-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (kcell-view:reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 nil (and (boundp 'default-dir) default-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (let ((hargs:reading-p 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (list (hargs:at-p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ((eolp) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ((and (eq hargs:reading-p 'hmenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (eq (selected-window) (minibuffer-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (if (search-backward " " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (progn (skip-chars-forward " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ((hargs:completion t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ((eq hargs:reading-p 'ebut) (ebut:label-p 'as-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ((ebut:label-p) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ((eq hargs:reading-p 'file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (cond ((hpath:at-p nil 'non-exist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ((eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (let ((file (dired-get-filename nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (and file (hpath:absolute-to file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ((eq major-mode 'monkey-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let ((file (monkey-filename t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (and file (hpath:absolute-to file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Delimited file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ((hpath:at-p 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; Unquoted remote file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ((hpath:is-p (hpath:ange-ftp-at-p) 'file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (no-default nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ((buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ((eq hargs:reading-p 'directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (cond ((hpath:at-p 'directory 'non-exist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ((eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (let ((dir (dired-get-filename nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (and dir (setq dir (hpath:absolute-to dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (file-directory-p dir) dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ((eq major-mode 'monkey-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((dir (monkey-filename t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (and dir (setq dir (hpath:absolute-to dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (file-directory-p dir) dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; Delimited directory name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ((hpath:at-p 'directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; Unquoted remote directory name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ((hpath:is-p (hpath:ange-ftp-at-p) 'directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (no-default nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ((eq hargs:reading-p 'string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (or (hargs:delimited "\"" "\"") (hargs:delimited "'" "'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (hargs:delimited "`" "'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ((or (eq hargs:reading-p 'actype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (eq hargs:reading-p 'actypes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (let ((name (find-tag-default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (car (set:member name (htype:names 'actypes)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ((or (eq hargs:reading-p 'ibtype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (eq hargs:reading-p 'ibtypes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let ((name (find-tag-default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (car (set:member name (htype:names 'ibtypes)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ((eq hargs:reading-p 'sexpression) (hargs:sexpression-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ((eq hargs:reading-p 'Info-node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (and (eq major-mode 'Info-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (let ((file (hpath:relative-to Info-current-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Info-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (and (stringp file) (string-match "^\\./" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq file (substring file (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (concat "(" file ")" Info-current-node))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ((eq hargs:reading-p 'mail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (and (hmail:reader-p) buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (prin1-to-string (list (rmail:msg-id-get) buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ((eq hargs:reading-p 'symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let ((sym (find-tag-default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (or (fboundp sym) (boundp sym)) sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ((eq hargs:reading-p 'buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (find-tag-default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ((eq hargs:reading-p 'character)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ((eq hargs:reading-p 'key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (require 'hib-kbd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (let ((key-seq (hbut:label-p 'as-label "{" "}")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (and key-seq (kbd-key:normalize key-seq))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ((eq hargs:reading-p 'integer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (save-excursion (skip-chars-backward "-0-9")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (looking-at "-?[0-9]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (read (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun hargs:completion (&optional no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 "If in the completions buffer, return completion at point. Also insert unless optional NO-INSERT is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 Insert in minibuffer if active or in other window if minibuffer is inactive."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (interactive '(nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if (or (equal (buffer-name) "*Completions*") ;; V19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (equal (buffer-name) " *Completions*")) ;; V18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (owind (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if (re-search-backward "^\\|[ \t][ \t]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (let ((insert-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (cond ((> (minibuffer-depth) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ((not (eq (selected-window) (next-window nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (next-window nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (bury-completions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (if (and insert-window (looking-at "[^\t\n]+"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (progn (setq entry (buffer-substring (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (select-window insert-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((str (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if (and (eq (selected-window) (minibuffer-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; If entry matches tail of minibuffer prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; already, then return minibuffer contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; as entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (regexp-quote entry) "\\'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (if (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "/[^/]+\\'" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 str 0 (1+ (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (or no-insert (if entry (insert entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; In buffer, non-minibuffer completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; Only insert entry if last buffer line does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; not end in entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (cond (no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ((or (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (regexp-quote entry) "\\'") str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (null entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq bury-completions t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (t (insert entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (select-window owind) (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if bury-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (progn (bury-buffer nil) (delete-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 entry)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defun hargs:iform-read (iform &optional modifying)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "Reads action arguments according to IFORM, a list with car = 'interactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 Optional MODIFYING non-nil indicates current button is being modified, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 button's current values should be presented as defaults. Otherwise, uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 hargs:defaults as list of defaults, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 See also documentation for 'interactive'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; This is mostly a translation of 'call-interactively' to Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; Save this now, since use of minibuffer will clobber it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (setq prefix-arg current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (if (not (and (listp iform) (eq (car iform) 'interactive)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "(hargs:iform-read): arg must be a list whose car = 'interactive.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setq iform (car (cdr iform)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (if (or (null iform) (and (stringp iform) (equal iform "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (let ((prev-reading-p hargs:reading-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq hargs:reading-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (if (not (stringp iform))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (let ((defaults (if modifying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (hattr:get 'hbut:current 'args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (and (boundp 'hargs:defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (listp hargs:defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 hargs:defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (eval iform))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (let ((i 0) (start 0) (end (length iform))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (ientry) (results) (val) (default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defaults (if modifying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (hattr:get 'hbut:current 'args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (and (boundp 'hargs:defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (listp hargs:defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 hargs:defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;; Handle special initial interactive string chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; '*' means error if buffer is read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Notion of when action cannot be performed due to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; read-only buffer is view-specific, so here, we just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; ignore a read-only specification since it is checked for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; earlier by any ebut edit code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; '@' means select window of last mouse event.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; '_' means keep region in same state (active or inactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; after this command. (XEmacs only.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (while (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ((eq (aref iform i) ?*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ((eq (aref iform i) ?@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (hargs:select-event-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ((eq (aref iform i) ?_)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq zmacs-region-stays t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (setq i (1+ i) start i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (while (and (< start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (string-match "\n\\|\\'" iform start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (setq start (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ientry (substring iform i (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 i start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 default (car defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 default (if (or (null default) (stringp default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (prin1-to-string default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 val (hargs:get ientry default (car results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 defaults (cdr defaults)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 results (cond ((or (null val) (not (listp val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (cons val results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; Is a list of args?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ((eq (car val) 'args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (append (nreverse (cdr val)) results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (t;; regular list value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (cons val results)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (nreverse results))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq hargs:reading-p prev-reading-p))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (defun hargs:read (prompt &optional predicate default err val-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 "PROMPTs without completion for a value matching PREDICATE and returns it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 PREDICATE is an optional boolean function of one argument. Optional DEFAULT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 is a string to insert after PROMPT as the default return value. Optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ERR is a string to display temporarily when an invalid value is given.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Optional VAL-TYPE is a symbol indicating type of value to be read. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 VAL-TYPE is not equal to 'sexpression' or 'klink' and is non-nil, value is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 returned as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (let ((bad-val) (val) (stringify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (prev-reading-p hargs:reading-p) (read-func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (owind (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (cond ((or (null val-type) (eq val-type 'sexpression))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (setq read-func 'read-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 hargs:reading-p 'sexpression))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (t (setq read-func 'read-string hargs:reading-p val-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 stringify t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (while (progn (and default (not (stringp default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (setq default (prin1-to-string default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (or bad-val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (setq val (funcall read-func prompt default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (error (setq bad-val t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (if bad-val t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (and stringify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; Remove any double quoting of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "\\`\"\\([^\"]*\\)\"\\'" val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq val (substring val (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (and predicate (not (funcall predicate val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (if bad-val (setq bad-val nil) (setq default val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if err (progn (message err) (sit-for 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (setq hargs:reading-p prev-reading-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (select-window owind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (switch-to-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (defun hargs:read-match (prompt table &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 predicate must-match default val-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 "PROMPTs with completion for a value in TABLE and returns it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 TABLE is an alist where each element's car is a string, or it may be an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 obarray for symbol-name completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 Optional PREDICATE limits table entries to match against.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 Optional MUST-MATCH means value returned must be from TABLE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 Optional DEFAULT is a string inserted after PROMPT as default value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 Optional VAL-TYPE is a symbol indicating type of value to be read."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (if (and must-match (null table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (let ((prev-reading-p hargs:reading-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (owind (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (setq hargs:reading-p (or val-type t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (completing-read prompt table predicate must-match default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq hargs:reading-p prev-reading-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (select-window owind)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (switch-to-buffer obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (defun hargs:select-p (&optional value assist-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "Returns optional VALUE or value selected at point if any, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 If value is the same as the contents of the minibuffer, it is used as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 the current minibuffer argument, otherwise, the minibuffer is erased
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 and value is inserted there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 Optional ASSIST-FLAG non-nil triggers display of Hyperbole menu item help when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 appropriate."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (if (and (> (minibuffer-depth) 0) (or value (setq value (hargs:at-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (let ((owind (selected-window)) (back-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (str-value (and value (format "%s" value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (select-window (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (set-buffer (window-buffer (minibuffer-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;; Selecting a menu item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ((eq hargs:reading-p 'hmenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (if assist-flag (setq hargs:reading-p 'hmenu-help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (hui:menu-enter str-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;; Use value for parameter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ((string= str-value (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (exit-minibuffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; Clear minibuffer and insert value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (t (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (erase-buffer) (insert str-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (setq back-to t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (if back-to (select-window owind))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ;;; From etags.el, so don't have to load the whole thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (or (fboundp 'find-tag-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defun find-tag-default ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (or (and (boundp 'find-tag-default-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (not (memq find-tag-default-hook '(nil find-tag-default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (condition-case data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (funcall find-tag-default-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (message "value of find-tag-default-hook signalled error: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (if (not (memq (char-syntax (preceding-char)) '(?w ?_)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (while (not (looking-at "\\sw\\|\\s_\\|\\'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (while (looking-at "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if (re-search-backward "\\sw\\|\\s_" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (regexp-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (progn (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (progn (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (while (looking-at "\\s'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 nil)))))
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 hargs:action-get (action modifying)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 "Interactively gets list of arguments for ACTION's parameters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Current button is being modified when MODIFYING is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 Returns nil if ACTION is not a list or byte-code object, has no interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 form or takes no arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (and (or (hypb:v19-byte-code-p action) (listp action))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (let ((interactive-form (action:commandp action)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if interactive-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (action:path-args-rel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (hargs:iform-read interactive-form modifying))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (defun hargs:delimited (start-delim end-delim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 &optional start-regexp-flag end-regexp-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 "Returns a single line, delimited argument that point is within, or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 START-DELIM and END-DELIM are strings that specify the argument delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 With optional START-REGEXP-FLAG non-nil, START-DELIM is treated as a regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 expression. END-REGEXP-FLAG is similar."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (let* ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (limit (if start-regexp-flag opoint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (+ opoint (1- (length start-delim)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (start-search-func (if start-regexp-flag 're-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 'search-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (end-search-func (if end-regexp-flag 're-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 'search-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (while (and (setq start (funcall start-search-func start-delim limit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (< (point) opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; This is not to find the real end delimiter but to find
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; end delimiters that precede the current argument and are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; therefore false matches, hence the search is limited to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; prior to the original point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (funcall end-search-func end-delim opoint t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (if start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (end-of-line) (setq limit (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (and (funcall end-search-func end-delim limit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (setq end (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (buffer-substring start end)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (defun hargs:get (interactive-entry &optional default prior-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 "Prompts for an argument, if need be, from INTERACTIVE-ENTRY, a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 Optional DEFAULT is inserted after prompt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 First character of INTERACTIVE-ENTRY must be a command character from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 the list in the documentation for 'interactive' or a `+' which indicates that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 the following character is a Hyperbole interactive extension command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 May return a single value or a list of values, in which case the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 element of the list is always the symbol 'args."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (let (func cmd prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (cond ((or (null interactive-entry) (equal interactive-entry ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (error "(hargs:get): Empty interactive-entry arg."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ((= (aref interactive-entry 0) ?+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; Hyperbole / user extension command character. The next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; character is the actual command character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (setq cmd (aref interactive-entry 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 prompt (format (substring interactive-entry 2) prior-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 func (if (< cmd (length hargs:iform-extensions-vector))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (aref hargs:iform-extensions-vector cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (if func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (funcall func prompt default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 "(hargs:get): Bad interactive-entry extension character: '%c'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (t (setq cmd (aref interactive-entry 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (format (substring interactive-entry 1) prior-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 func (if (< cmd (length hargs:iform-vector))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (aref hargs:iform-vector cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (if func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (funcall func prompt default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 "(hargs:get): Bad interactive-entry command character: '%c'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 cmd))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (defun hargs:make-iform-vector (iform-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 "Return a vector built from IFORM-ALIST used for looking up interactive command code characters."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; Vector needs to have 1 more elts than the highest char code for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; interactive commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (let* ((size (1+ (car (sort (mapcar 'car iform-alist) '>))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (vec (make-vector size nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (aset vec (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (` (lambda (prompt default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (setq hargs:reading-p '(, (car (cdr elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (, (cdr (cdr elt))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 iform-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 vec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (defun hargs:prompt (prompt default &optional default-prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 "Returns string of PROMPT including DEFAULT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 Optional DEFAULT-PROMPT is used to describe default value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (format "%s(%s%s%s) " prompt (or default-prompt "default")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (equal default "") "" " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (defun hargs:select-event-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 "Select window, if any, that mouse was over during last event."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (if hyperb:lemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (if current-mouse-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (or (event-window current-mouse-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (let* ((event last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (window (posn-window (event-start event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (if (and (eq window (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (not (minibuffer-window-active-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (minibuffer-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (error "Attempt to select inactive minibuffer window")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (or window (selected-window)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (defun hargs:sexpression-p (&optional no-recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 "Returns an sexpression at point as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 If point follows an sexpression end character, the preceding sexpression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 is returned. If point precedes an sexpression start character, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 following sexpression is returned. Otherwise, the innermost sexpression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 that point is within is returned or nil if none."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (let ((not-quoted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 '(not (and (= (char-syntax (char-after (- (point) 2))) ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (/= (char-syntax (char-after (- (point) 3))) ?\\)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (cond ((and (= (char-syntax (preceding-char)) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; Ignore quoted end chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (eval not-quoted))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (progn (forward-sexp -1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ((and (= (char-syntax (following-char)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; Ignore quoted begin chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (eval not-quoted))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (progn (forward-sexp) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (no-recurse nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (t (save-excursion (up-list 1) (hargs:sexpression-p t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (defvar hargs:iforms nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 "Alist of (interactive-cmd-chr . (argument-type . get-argument-form)) elts.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (setq hargs:iforms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; Get function symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (?a . (symbol .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (intern (completing-read prompt obarray 'fboundp t default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 ;; Get name of existing buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (?b . (buffer .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (or default (setq default (other-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (read-buffer prompt default t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; Get name of possibly nonexistent buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (?B . (buffer .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (or default (setq default (other-buffer (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (read-buffer prompt default nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;; Get character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (?c . (character .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (progn (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (hargs:prompt prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (if (integerp default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (char-to-string default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 "Curr:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (char-to-string (read-char)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;; Get symbol for interactive function, a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (?C . (symbol .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (intern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (completing-read prompt obarray 'commandp t default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;; Get value of point; does not do I/O.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (?d . (integer . (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;; Get directory name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (?D . (directory .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (or default (setq default default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (read-file-name prompt default default 'existing))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;; Get existing file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (?f . (file .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (read-file-name prompt default default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 nil 'existing))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ;; Get possibly nonexistent file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (?F . (file . (read-file-name prompt default default nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; Get key sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (?k . (key .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (key-description (read-key-sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (hargs:prompt prompt default "Curr:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 prompt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ;; Get key sequence without converting uppercase or shifted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ;; function keys to their unshifted equivalents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (?K . (key .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (key-description (read-key-sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (hargs:prompt prompt default "Curr:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;; Get value of mark. Does not do I/O.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (?m . (integer . (marker-position (hypb:mark-marker t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; Get numeric prefix argument or a number from the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (?N . (integer .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (if prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (prefix-numeric-value prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (let ((arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (while (not (integerp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (setq arg (read-minibuffer prompt default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;; Get number from minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (?n . (integer .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (let ((arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (while (not (integerp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (setq arg (read-minibuffer prompt default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; Get numeric prefix argument. No I/O.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (?p . (prefix-arg .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (prefix-numeric-value prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; Get prefix argument in raw form. No I/O.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (?P . (prefix-arg . prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; Get region, point and mark as 2 args. No I/O
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (?r . (region .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (if (marker-position (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (list 'args (min (point) (hypb:mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (max (point) (hypb:mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (list 'args nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;; Get string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (?s . (string . (read-string prompt default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 ;; Get symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (?S . (symbol .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 prompt default minibuffer-local-ns-map 'sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; Get variable name: symbol that is user-variable-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (?v . (symbol . (read-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (hargs:prompt prompt default "Curr:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 prompt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;; Get Lisp expression but don't evaluate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (?x . (sexpression . (read-minibuffer prompt default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; Get Lisp expression and evaluate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (?X . (sexpression . (eval-minibuffer prompt default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (defvar hargs:iform-vector nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 "Vector of forms for each interactive command character code.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (setq hargs:iform-vector (hargs:make-iform-vector hargs:iforms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (defvar hargs:iforms-extensions nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 "Hyperbole extension alist of (interactive-cmd-chr . (argument-type . get-argument-form)) elts.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (setq hargs:iforms-extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ;; Get existing Info node name and file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (?I . (Info-node .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (let (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (require 'info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (hargs:read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (lambda (node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (and (string-match "^(\\([^\)]+\\))" node)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (setq file (substring node (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (memq t (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (lambda (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (file-readable-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (hpath:absolute-to file dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (if (boundp 'Info-directory-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 Info-directory-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (list Info-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 "(hargs:read): Use (readable-filename)nodename."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 'Info-node))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;; Get kcell from koutline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (?K . (kcell . (hargs:read prompt nil default nil 'kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;; Get kcell or path reference for use in a link.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (?L . (klink . (hargs:read prompt nil default nil 'klink)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;; Get existing mail msg date and file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (?M . (mail . (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (or (not (listp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (setq default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (read-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (hargs:prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 prompt ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 "list of (date mail-file)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (/= (length default) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (not (and (stringp (car (cdr default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (car (cdr default))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 default)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (defvar hargs:iform-extensions-vector nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 "Vector of forms for each interactive command character code.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (setq hargs:iform-extensions-vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (hargs:make-iform-vector hargs:iforms-extensions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (provide 'hargs)