annotate lisp/hyperbole/hib-kbd.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: hib-kbd.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Implicit button type for key sequences delimited with {}.
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: 22-Nov-91 at 01:37:57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 23-Oct-95 at 05:02:49 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 ;; A click of the Hyperbole execution key on a key sequence executes its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; command binding.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; A click of the Hyperbole help key on a key sequence displays the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; documentation for its command binding.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Key sequences should be in human readable form, e.g. {C-b}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Forms such as {\C-b}, {\^b}, and {^b} will not be recognized.
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 ;;; Public implicit button types
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 (defact kbd-key (key-sequence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "Executes the function binding for KEY-SEQUENCE, delimited by {}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Returns t if a KEY-SEQUENCE has a binding, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (interactive "kKeyboard key to execute (no {}): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (kbd-key:act key-sequence))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defib kbd-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 "Executes a key sequence delimited by curly braces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Key sequences should be in human readable form, e.g. {C-b}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 Forms such as {\C-b}, {\^b}, and {^b} will not be recognized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (if (br-in-browser)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (let* ((seq-and-pos (or (hbut:label-p t "{`" "'}" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (hbut:label-p t "{" "}" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (key-sequence (car seq-and-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (binding (and (stringp key-sequence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (key-binding (kbd-key:normalize key-sequence)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (and binding (not (integerp binding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (ibut:label-set seq-and-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (hact 'kbd-key key-sequence)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; Public functions
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 kbd-key:act (key-sequence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Executes the command binding for KEY-SEQUENCE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Returns t if KEY-SEQUENCE has a binding, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (interactive "kKeyboard key to execute (no {}): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq current-prefix-arg nil) ;; kbd-key:normalize below sets it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (let ((binding (key-binding (kbd-key:normalize key-sequence))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (cond ((null binding) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ((memq binding '(action-key action-mouse-key hkey-either))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (message "(kbd-key:act): This key does what the Action Key does.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (t (call-interactively binding) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defun kbd-key:doc (key &optional full)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 "Shows first line of doc for binding of keyboard KEY in minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 With optional FULL, displays full documentation for command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (interactive "kKey sequence: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (let* ((cmd (let ((cmd (key-binding (kbd-key:normalize key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (if (not (integerp cmd)) cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (doc (and cmd (documentation cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (end-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if doc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (or full
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (setq end-line (string-match "[\n]" doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 doc (substitute-command-keys (substring doc 0 end-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq doc (format "No documentation for {%s} %s" key (or cmd ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (and cmd doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if full
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (describe-function cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (message doc)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defun kbd-key:help (but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Display documentation for binding of keyboard key given by BUT's label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (let ((kbd-key (hbut:key-to-label (hattr:get but 'lbl-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (and kbd-key (kbd-key:doc kbd-key 'full))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun kbd-key:normalize (key-sequence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "Returns KEY-SEQUENCE normalized into a form that can be parsed by commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (interactive "kKeyboard key sequence to normalize (no {}): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (let ((norm-key-seq (copy-sequence key-sequence))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (case-fold-search nil) (case-replace t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Quote Control and Meta key names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "[ \t\n\^M]+" norm-key-seq "" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "@key{SPC}\\|SPC" norm-key-seq "\040" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "@key{DEL}\\|DEL" norm-key-seq "\177" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 "@key{RET}\\|@key{RTN}\\|RET\\|RTN"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 norm-key-seq "\015" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "ESCESC" norm-key-seq "\233" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "@key{ESC}\\|ESC" norm-key-seq "M-" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; Unqote special {} chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 norm-key-seq (hypb:replace-match-string "\\\\\\([{}]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 norm-key-seq "\\1")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (while (string-match "\\`\\(C-u\\|M-\\)\\(-?[0-9]+\\)" norm-key-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (string-to-int (substring norm-key-seq (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 norm-key-seq (substring norm-key-seq (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let (arg-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (while (string-match "\\`C-u" norm-key-seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if (or (not (listp current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (not (integerp (setq arg-val (car current-prefix-arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq current-prefix-arg '(1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 arg-val 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (setq arg-val (* arg-val 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 current-prefix-arg (cons arg-val nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 norm-key-seq (substring norm-key-seq (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq norm-key-seq (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "C-\\(.\\)" norm-key-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (lambda (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (1+ (- (downcase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (string-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (substring str (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (1+ (match-beginning 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ?a)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "M-\\(.\\)" norm-key-seq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (lambda (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (char-to-string (+ (downcase (string-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (substring str (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (1+ (match-beginning 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 128)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (provide 'hib-kbd)