]> git.donarmstrong.com Git - lib.git/blob - emacs_el/tiny-tools/tiny/tinyef.el
add tiny-tools
[lib.git] / emacs_el / tiny-tools / tiny / tinyef.el
1 ;;; tinyef.el --- (E)lectric (f)ile minor mode. Easy C-x C-f filename composing
2
3 ;; This file is not part of Emacs
4
5 ;;{{{ Id
6
7 ;; Copyright (C)    1995-2007 Jari Aalto
8 ;; Keywords:        extensions
9 ;; Author:          Jari Aalto
10 ;; Maintainer:      Jari Aalto
11 ;;
12 ;; To get information on this program call M-x tinyef-version.
13 ;; Look at the code with folding.el
14
15 ;; COPYRIGHT NOTICE
16 ;;
17 ;; This program is free software; you can redistribute it and/or modify it
18 ;; under the terms of the GNU General Public License as published by the Free
19 ;; Software Foundation; either version 2 of the License, or (at your option)
20 ;; any later version.
21 ;;
22 ;; This program is distributed in the hope that it will be useful, but
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25 ;; for more details.
26 ;;
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with program; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
30 ;; Boston, MA 02110-1301, USA.
31 ;;
32 ;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information
33
34 ;;}}}
35 ;;{{{ Install
36
37 ;; ....................................................... &t-install ...
38 ;; Put this file on your emacs-lisp load path, add following into your
39 ;; ~/.emacs startup file
40 ;;
41 ;;      (add-hook 'tinyef-load-hook 'tinyef-minibuffer-define-key-extras)
42 ;;      (require 'tinyef)
43 ;;
44 ;; Or use this autoload choice and your ~/.emacs will load quicker.
45 ;; This is the preferred method:
46 ;;
47 ;;      (add-hook 'tinyef-load-hook 'tinyef-minibuffer-define-key-extras)
48 ;;      (autoload 'turn-on-tinyef-mode "tinyef" "" t)
49 ;;      (add-hook 'minibuffer-setup-hook 'turn-on-tinyef-mode)
50 ;;
51 ;; If you have any questions, use this function to contact maintainer
52 ;;
53 ;;      M-x tinyef-submit-bug-report
54
55 ;;}}}
56
57 ;;{{{ Documentation
58
59 ;; ..................................................... &t-commentary ...
60
61 ;;; Commentary:
62
63 ;;  Preface, Apr 1995
64 ;;
65 ;;      There was a post in gnu.emacs.sources where Anders Lindgren
66 ;;      <andersl@csd.uu.se> presented the basic code that allowed electric
67 ;;      ~ and electric / characters to wipe out full (mini)buffer in certain
68 ;;      cases. What you see here, is complete rewrite and enchancement of
69 ;;      that code. This is a real must for any minibuffer file handling.
70 ;;
71 ;;  Overview of features
72 ;;
73 ;;      o   Easy filename editing. Deletes directories at time, delete line
74 ;;          backward, electric tilde, electric slash, electric colon etc.
75 ;;      o   Useful to go along with `C-x' `C-f' command prompt.
76 ;;      o   Mouse-3 in minibuffers clears the input.
77 ;;
78 ;;  Description
79 ;;
80 ;;      This package is only slightly *electric*, in a sense that it only
81 ;;      defines some keys to be electric and it needs some other keys
82 ;;      solely to its own use (you can't insert these chars to buffer
83 ;;      without `C-q' `CHAR'). The term electric refers to feature where a
84 ;;      pressed character behaves differently if the pressing happens
85 ;;      around certain other charcters (some condition is met which
86 ;;      triggers this other behavior). Other than that, the character
87 ;;      behaves normally. Below there is a sample graph to give you an
88 ;;      overview of what the so called "electricity" is is practice. In
89 ;;      these presented cases cursor it at the end of line. Jusr load this
90 ;;      file, press `C-x' `C-f' and experiment with keys "<>|/~".
91 ;;
92 ;;      o   b>> means what's on the line *before*
93 ;;      o   a>> means what's there *after*
94 ;;      o   ""  means what you just pressed
95 ;;      o   []  means which action the character triggered
96 ;;
97 ;;      Delete actions:
98 ;;
99 ;;          b>> ~/dir1/dir2/dir3/                       "<" [step-delete-back]
100 ;;          a>> ~/dir1/dir2/
101 ;;          The action wiped previous directory name or until
102 ;;          special mark, See code, defaults are  ":/@" (ange-ftp things)
103 ;;
104 ;;          b>> ~/dir1/dir2/dir3/                       ">" [step-delete-fwd]
105 ;;                     *Cursor here
106 ;;          a>> ~/dir1/dir3/
107 ;;          The action wiped one directory forward.
108 ;;
109 ;;          b>> ~/dir1/dir2/                            "|" [chunk-delete]
110 ;;          a>>
111 ;;          The action deleted whole line. It deletes until special marks
112 ;;          like "@:". If repeated, it deletes constantly backward
113 ;;
114 ;;      Electric actions:
115 ;;
116 ;;          b>> http:/www.site.com/~userFoo/dir1/dir2/dir3/ "/" [e-slash]
117 ;;          a>> http:/
118 ;;          The e-slash action wiped out the line, because writing
119 ;;          two slashes normally indicates, that you want to give
120 ;;          another path
121 ;;
122 ;;          b>> ~/dir1/dir2/dir3/                       "~" [e-tilde]
123 ;;          a>> ~
124 ;;          The action wiped the line away, because it assumed
125 ;;          you want to give "~userFoo" or another "~" relative path
126 ;;
127 ;;      Movement actions:
128 ;;
129 ;;          b>> ~/dir1/dir2/dir3/                       "'" [move-back]
130 ;;                              *Cursor here
131 ;;          a>> ~/dir1/dir2/dir3/
132 ;;                          *Cursor here
133 ;;          The cursor goes backward logical steps.
134 ;;
135 ;;          b>> ~/dir1/dir2/dir3/                       "*" [move-fwd]
136 ;;                     *Cursor here
137 ;;          a>> ~/dir1/dir2/dir3/
138 ;;                          *Cursor here
139 ;;          The cursor goes forward logical steps.
140 ;;
141 ;;      Other minibuffer keys that you can activate with:
142 ;;
143 ;;          (add-hook 'tinyef-load-hook 'tinyef-minibuffer-define-key-extras)
144 ;;
145 ;;      o  `C-c' `C-b'  Insert most recent buffer name to prompt
146 ;;      o  `C-c' `C-d'  Insert date: ISO8601 YY-MM-DD--HH-MM into prompt
147 ;;      o  `C-c' `C-f'  Insert most recent buffer's file name to prompt
148 ;;      o  `C-c' `\t'   Complete from minibuffer history
149 ;;
150 ;;  Automatic Isntallation
151 ;;
152 ;;      This file includes function `tinyef-install' which hooks the mode
153 ;;      to the appropriate places. E.g. to your minibuffer. If you're in
154 ;;      trouble, you can always turn this mode off with the supplied
155 ;;      hotkey, which is by default `C-c' `/'. You can't "see" whether mode
156 ;;      is on or off in minibuffer, since it doesn't have its own mode
157 ;;      line. But calling the hotkey will tell you the state change. You
158 ;;      can also remove this mode completely from your emacs if you need to
159 ;;      do that in emergencies. just call following function with some
160 ;;      prefix argument like `C-u' to `tinyef-install'
161 ;;
162 ;;  Mouse bindings in minibuffer
163 ;;
164 ;;      When this package loads, it calls function `tinyef-install-mouse'
165 ;;      which defines following bindings to your minibuffer
166 ;;
167 ;;      o   Mouse-3 = BIG erase backward from point
168 ;;      o   C-mouse-1 = Small delete backward
169 ;;
170 ;;      This should give your free hands to cut, paste and Delete, without
171 ;;      lifting your hand off the mouse.
172
173 ;;}}}
174
175 ;;; Change Log:
176
177 ;;; Code:
178
179 ;;{{{ setup: require
180
181 (require 'tinylibm)
182
183 (eval-when-compile
184   (ti::package-use-dynamic-compilation))
185
186 (eval-and-compile
187   (autoload 'apropos-internal "apropos"))
188
189 (ti::package-defgroup-tiny TinyEf tinyef-: extensions
190   "Electric file minor mode. Designed for minibuffer file prompt editing.
191   Overview of features
192
193         o   Easy filename editing. Deletes directories at time, delete line
194             backward, electric tilde, electric slash, electric colon etc.
195         o   This is useful e.g. in minibuffer's C-x C-f promt
196     ")
197
198 ;;}}}
199 ;;{{{ setup: variables
200
201 (defcustom tinyef-:load-hook nil
202   "*Hook that is run when package is loaded."
203   :type  'hook
204   :group 'TinyEf)
205
206 (defcustom tinyef-:mode-key "\C-c/"
207   "*Key to toggle function `tinyef-mode' on/off in minibuffer map."
208   :type  '(string :tag "Key sequence")
209   :group 'TinyEf)
210
211 (defcustom tinyef-:mode-key-table
212   '((?\<   . step-delete-back)
213     (?\>   . step-delete-fwd)
214     (?\|   . chunk-delete)
215     (?\;   . move-back)
216     (?\'   . move-fwd)
217     (?\~   . e-tilde)                   ;electric keys
218     (?\/   . e-slash)
219     (?\$   . e-dollar))
220   "*Map keys to actions.
221 Refer source file's default values for action names.
222 If you change this; you must call function \\[tinyef-mode-map-define-keys]."
223   :type '(repeat
224           (list
225            (character :tag "Electric char")
226            (choice
227             :tag "Action"
228             (const step-delete-back)
229             (const step-delete-fwd)
230             (const chunk-delete)
231             (const move-back)
232             (const move-fwd)
233             (const e-tilde)
234             (const e-slash)
235             (const e-dollar)
236             (const undo))))
237   :group 'TinyEf)
238
239 (defcustom tinyef-:step-delete-chars "-./@:"
240   "*When using step-delete action, kill until these chars. This is charset.
241 The \"-\" character must be first in the string."
242   :type '(string "Charset")
243   :group 'TinyEf)
244
245 (defcustom tinyef-:mode-defined-maps ;== if you need to change this; report
246   (delq nil                             ;== change to maintainer
247         (list
248          'global-map
249          'read-expression-map
250          'minibuffer-local-map
251          'minibuffer-local-must-match-map ;eg C-x C-f uses this
252          'minibuffer-local-completion-map
253          ;;  Only in Emacs
254          ;;  the minibuffer when spaces are not allowed
255          (if (boundp 'minibuffer-local-ns-map)
256              'minibuffer-local-ns-map)))
257   "*Keymap list where to install Electric file minor mode hotkey-
258 See `tinyef-:mode-key'."
259   :type  '(symbol :tag "Keymap")
260   :group 'TinyEf)
261
262 ;;}}}
263 ;;{{{ version
264
265 (eval-and-compile
266   (ti::macrof-version-bug-report
267    "tinyef.el"
268    "tinyef"
269    tinyef-:version-id
270    "$Id: tinyef.el,v 2.42 2007/05/01 17:20:43 jaalto Exp $"
271    '(tinyef-:version-id
272      tinyef-:load-hook
273      tinyef-:mode-hook
274      tinyef-mode
275      tinyef-:mode-map
276      tinyef-:mode-defined-maps
277      tinyef-:mode-name
278      tinyef-:mode-key-table)))
279
280 ;;}}}
281 ;;{{{ code: misc, keys, install
282
283 ;;;###autoload (autoload 'tinyef-mode           "tinyef" "" t)
284 ;;;###autoload (autoload 'turn-off-tinyef-mode  "tinyef" "" t)
285 ;;;###autoload (autoload 'turn-on-tinyef-mode   "tinyef" "" t)
286 ;;;###autoload (autoload 'tinyef-commentary     "tinyef" "" t)
287 ;;;###autoload (autoload 'tinyef-version        "tinyef" "" t)
288
289 (eval-and-compile
290
291   (ti::macrof-minor-mode-wizard
292    "tinyef-" " Tef" nil "Tef" 'TinyEf "tinyef-:" ;1-6
293
294    "Electric file name mode.
295 This mode helps you composing filename more easily. Some keys
296 are \"electric\", meaning that they have two behavior. By default
297 character \"~/$\" are electric. Some other keys have special meaning and you
298 cannot insert them into buffer unless you press C-q before the key-.
299 These special keys do are mapped to movement keys and delete keys.
300
301 See variable `tinyef-:mode-key-table' which specifies actions
302 for each electric character. Consult also `tinyef-:step-delete-chars'.
303 The default action table is as follows:
304
305     (setq tinyef-:mode-key-table
306       '((?\<   . step-delete-back)              ;KEY -- action symbol
307         (?\>   . step-delete-fwd)
308         (?|    . chunk-delete)
309         (?\;   . move-back)
310         (?\'   . move-fwd)
311         (?\~   . e-tilde)                       ;electric keys
312         (?\/   . e-slash)
313         (?\$   . e-dollar)))
314
315 Here is smple graph to give you an overview of what this mode does.
316 In these presented cases cursor it at the end of line.
317 Alternatively, just load this file, press C-x C-f and experiment
318 with keys `[]\/~'.
319
320 o   b>> means what's on the line *before*
321 o   a>> means what's there *after*
322 o   `'  means what you just pressed
323 o   []  means which action the character triggered
324
325     b>> http:/www.site.com/~userFoo/dir1/dir2/dir3/ `/` [e-slash]
326     a>> http:/
327     The e-slash action wiped out the line, because writing
328     two slashes normally indicates, that you want to give
329     another path
330
331     b>> ~/dir1/dir2/dir3/                       `~' [e-tilde]
332     a>> ~
333     The action wiped the line away, because it assumed
334     you want to give `~userFoo or another `~' relative path
335
336     b>> ~/dir1/dir2/dir3/                       `[' [step-delete-back]
337     a>> ~/dir1/dir2/
338     The action wiped previous directory name or until
339     special mark, See code, defaults are  `:/@' (ange-ftp things)
340
341     b>> ~/dir1/dir2/                            `=' [undo]
342     a>> ~/dir1/dir2/dir3/
343     The action works like normal undo.
344
345     b>> ~/dir1/dir2/                            `\' [chunk-delete]
346     a>>
347     The action deleted whole line. It deletes until special marks
348     like `@:'. If repeated, it deletes constantly backward
349
350 Defined keys:
351
352 \\{tinyef-:mode-map}"
353
354    "Tief"
355    nil
356    "Electric file mode"
357    nil
358    nil))
359
360 ;;; ----------------------------------------------------------------------
361 ;;;
362 (defmacro tinyef-function-macro (action)
363   "Define interactive command ACTION."
364   (let* ((sym (intern (format "tinyef-%s" (symbol-name (` (, action)))))))
365     (`
366      (defun (, sym) ()
367        (interactive)
368        (tinyef-char nil (quote (, action)))))))
369
370 (tinyef-function-macro chunk-delete)
371 (tinyef-function-macro step-delete-back)
372
373 ;;; ----------------------------------------------------------------------
374 ;;;
375 (defsubst tinyef-key-p (map key)
376   "Test if function `tinyef-mode' is in MAP with KEY."
377   (eq 'tinyef-mode (lookup-key map key)))
378
379 ;;; ----------------------------------------------------------------------
380 ;;;
381 (defsubst tinyef-action (char)
382   "Return action for CHAR."
383   (cdr-safe (char-assq char tinyef-:mode-key-table)))
384
385 ;;; ----------------------------------------------------------------------
386 ;;;
387 (defun tinyef-install-maps (&optional remove force)
388   "Define Electric file mode's hot key. Optionally REMOVE.
389 The install is done only once, but you can FORCE reinstall.
390
391 See `tinyef-:mode-defined-maps'."
392   (let* ((key   tinyef-:mode-key)
393          (fun   'tinyef-mode)
394          map)
395     (dolist (x tinyef-:mode-defined-maps)
396       (setq map (eval x))
397       (if remove
398           ;; eval or symbol-value function
399           (if (tinyef-key-p (eval x) key)
400               (define-key (eval x) key nil))
401         (unless (get 'tinyef-install-maps 'installed)
402           (if (lookup-key map key)
403               (progn
404                 ;;(message "TinyMy: tinyef-:mode-key already taken in %s"
405                 ;;  (symbol-name x))
406                 nil)
407             (define-key (eval x) key fun)))))
408     ;; Mark as installed
409     (put 'tinyef-install-maps 'installed t)))
410
411 ;;; ----------------------------------------------------------------------
412 ;;;
413 (defun tinyef-mode-map-define-keys ()
414   "Define `tinyef-:mode-map' keys.
415 Always clears the keymap first and reinstalls the minor mode."
416   (interactive)
417   (setq tinyef-:mode-map  (make-sparse-keymap)) ;always refresh
418   ;;  Minor modes have copy of the keymap. Get rid of it and
419   ;;  replace it with new one.
420   (ti::keymap-add-minor-mode    'tinyef-mode nil nil    'remove)
421   (dolist (elt tinyef-:mode-key-table)
422     (define-key tinyef-:mode-map (char-to-string (car elt)) 'tinyef-char))
423   (ti::keymap-add-minor-mode 'tinyef-mode
424                              'tinyef-:mode-name
425                              tinyef-:mode-map))
426
427 ;;; ----------------------------------------------------------------------
428 ;;;
429 (defun tinyef-install (&optional arg)
430   "Install package. With optional ARG, cancel installation."
431   (interactive)
432   (tinyef-install-mouse arg)
433   (cond
434    (arg
435     (remove-hook        'minibuffer-setup-hook  'tinyef-minibuffer-setup)
436     (remove-hook        'minibuffer-exit-hook   'turn-off-tinyef-mode)
437
438     (ti::keymap-add-minor-mode 'tinyef-mode nil nil     'remove)
439     (tinyef-install-maps  'remove))
440    (t
441     (add-hook           'minibuffer-setup-hook  'tinyef-minibuffer-setup 'end)
442     (add-hook           'minibuffer-exit-hook   'turn-off-tinyef-mode    'end)
443     (tinyef-mode-map-define-keys)       ;installs also minor-mode
444     (tinyef-install-maps))))
445
446 ;;; ----------------------------------------------------------------------
447 ;;;
448 (defun tinyef-install-mouse  (&optional arg)
449   "Install default mouse binding. With ARG, remove."
450   (dolist (map (list
451                 minibuffer-local-map
452                 minibuffer-local-must-match-map
453                 minibuffer-local-completion-map))
454     (cond
455      ((ti::emacs-p)
456       ;; Have to bind down event; because MSB occupies it.
457       (define-key map [C-down-mouse-1] 'tinyef-step-delete-back)
458       (define-key map [C-down-mouse-3] 'undo)
459       (define-key map [mouse-3]        'tinyef-chunk-delete))
460      (t
461       (define-key map [(control button1)] 'tinyef-step-delete-back)
462       (define-key map [(control button3)] 'undo)
463       (define-key map [(button3)]         'tinyef-chunk-delete)))))
464
465 ;;}}}
466
467 ;;{{{ code: extra minibuffer commands
468
469 ;;; ----------------------------------------------------------------------
470 ;;;
471 (defun tinyef-buffer-name-not-minibuffer ()
472   "Return the name of current buffer, as a string.
473 If current buffer is the *mini-buffer* return name of previous-window."
474   (buffer-name (if (window-minibuffer-p)
475                    (if (eq (get-lru-window) (next-window))
476                        (window-buffer (previous-window))
477                      (window-buffer (next-window)))
478                  nil)))
479
480 ;;; ----------------------------------------------------------------------
481 ;;;
482 (defun tinyef-insert-buffer-name ()
483   "Insert buffer name of most recent buffer."
484   (interactive)
485   (insert (tinyef-buffer-name-not-minibuffer)))
486
487 ;;; ----------------------------------------------------------------------
488 ;;;
489 (defun tinyef-insert-buffer-dir-name ()
490   "Insert dir name of most recent buffer."
491   (interactive)
492   (let* ((bfn (buffer-file-name
493                (get-buffer (tinyef-buffer-name-not-minibuffer)))))
494     (if bfn
495         (insert (file-name-directory bfn)))))
496
497 ;;; ----------------------------------------------------------------------
498 ;;;
499 (defun tinyef-insert-buffer-file-name ()
500   "Insert file name of most recent buffer."
501   (interactive)
502   (let* ((bfn (buffer-file-name
503                (get-buffer (tinyef-buffer-name-not-minibuffer)))))
504     (if bfn
505         (insert bfn))))
506
507 ;;; ----------------------------------------------------------------------
508 ;;;
509 (defun tinyef-complete-from-minibuffer-history ()
510   "Take the history list and make it available as a `completions' buffer"
511   (interactive)
512   (with-output-to-temp-buffer "*Completions*"
513     (display-completion-list (symbol-value minibuffer-history-variable))
514     (save-excursion
515       (set-buffer standard-output)
516       (setq completion-base-size 0))))
517
518 ;;; ----------------------------------------------------------------------
519 ;;;
520 (defun tinyef-insert-current-date-time-minibuf ()
521   "Insert the current date and time."
522   (interactive)
523   (insert (format-time-string "%Y-%m-%d--%H%-%M" (current-time))))
524
525 ;;; ----------------------------------------------------------------------
526 ;;;
527 (defun tinyef-minibuffer-define-key-extras ()
528   "Define keys to minibuffer maps."
529   (dolist (map (apropos-internal
530                 "^mini"
531                 '(lambda (var)
532                    (and (boundp var)
533                         (keymapp (symbol-value var))))))
534     (setq map (symbol-value map))
535     (define-key map "\C-c\C-b" 'tinyef-insert-buffer-name)
536     (define-key map "\C-c\C-d" 'tinyef-insert-buffer-dir-name)
537     (define-key map "\C-c\C-f" 'tinyef-insert-buffer-file-name)
538     (define-key map "\C-c\C-t" 'tinyef-insert-current-date-time-minibuf)
539     (define-key map "\C-c\t"   'tinyef-complete-from-minibuffer-history)))
540
541 ;;}}}
542 ;;{{{ code: minibuffer
543
544 ;;; ----------------------------------------------------------------------
545 ;;; by Anders Lindgren.
546 ;;;
547 (defun tinyef-minibuffer-setup ()
548   "Turn on function `tinyef-mode' when entering minibuffer."
549   (setq
550    tinyef-mode
551    (if (boundp 'minibuffer-completion-table)
552        (eq minibuffer-completion-table 'read-file-name-internal)))
553   (if (and (boundp 'tinypair-mode)      ;Turn off TinyPair.el
554            (fboundp 'turn-off-tinypair-mode))
555       (ti::funcall 'turn-off-tinypair-mode)))
556
557 ;;}}}
558 ;;{{{ code: main
559
560 ;;; ----------------------------------------------------------------------
561 ;;;
562 (defun tinyef-step (&optional back)
563   "Position cursor, optionally BACK."
564   (let* ((set    tinyef-:step-delete-chars)
565          (rset   (concat "^" set))      ;reverse set
566          (func   (if back 'skip-chars-backward 'skip-chars-forward))
567          (point  (point))
568          limit)
569     (if back
570         (setq limit (line-beginning-position))
571       (setq limit (line-end-position)))
572     (funcall func rset limit)           ;do the movement
573     (when (eq (point) point)            ;not moved
574       (funcall func set  limit)
575       (funcall func rset limit))        ;try again
576     (when (not (eq (point) point))      ;moved ok
577       (when (and (null back) (not (eolp)))
578         ;; fix position a little
579         (forward-char 1)))))
580
581 ;;; ----------------------------------------------------------------------
582 ;;;
583 (defun tinyef-char (&optional character action)
584   "Handle Electric file mode's commands.
585 If there is no action for character insert it as is.
586 If this command is called interactively outside of minibuffer,
587 turn off function `tinyef-mode' and insert character as is.
588
589 Input:
590
591   CHARACTER  The character is read from input argument or it it is nil, then
592              `last-command-char' is used.
593   ACTION     If nil `tinyef-:mode-key-table' is consulted for character.
594              If non-nil, then should ve valid action symbol.
595
596 Current keymap:
597
598 \\{tinyef-:mode-map}"
599   (interactive)
600   (let* ((char          (or character last-command-char)) ;char pressed
601          (act           (or action (tinyef-action char)))
602          (re            '(".*@"  ".*:"))
603          (e-list        '(?/  ?@ ?\" ?\'))
604          (pnow          (point))
605          (point         (point))
606          str
607          eolp
608          bolp
609          hits)
610     (if (or (null act)                  ;no action recognized
611             (and (interactive-p)
612                  (not (eq (selected-window) (minibuffer-window)))
613                  (prog1 t
614                    (setq tinyef-mode nil))))
615         (insert char)
616       (setq bolp (line-beginning-position)  eolp (line-end-position))
617       ;; ... ... ... ... ... ... ... ... ... ... ... ...  e-kill-point . .
618       ;; find suitable kill point
619       (save-excursion
620         (beginning-of-line)
621         (dolist (regexp re)
622           (if (and (looking-at regexp)
623                    (not (eq eolp (match-end 0))))
624               (push (match-end 0)  hits)))
625         (if hits  (setq point (apply 'max hits))) ;;find longest position
626         (if (eq point eolp)                       ;;end of line ?
627             (setq point (point)))
628         (cond
629          ((eq pnow point)            ;no different than current point?
630           (setq str (buffer-substring bolp pnow))
631           ;;  make the end position not to go past string delimiter "
632           (if (not (string-match ".*\"" str))
633               (setq point bolp)
634             (setq point (+ bolp (match-end 0))))))) ;; cond-save-excursion
635       (cond
636        ;; ... ... ... ... ... ... ... ... ... ... ... ... ... ... undo ..
637        ((eq act 'undo)
638         (undo))
639        ;; ... ... ... ... ... ... ... ... ... ... ... ... ... .. chunk ..
640
641        ((eq act 'chunk-delete)
642         (delete-region point (point))) ;; The kill point is already set
643        ;; ... ... ... ... ... ... ... ... ... ... ... ... ... ... step ..
644        ((memq act '(step-delete-fwd move-fwd))
645         (setq point (point))
646         (tinyef-step)
647         (if (eq act 'step-delete-fwd)
648             (delete-region point (point))))
649        ((memq act '(step-delete-back move-back))
650         (setq point (point))
651         (tinyef-step 'back)
652         (if (eq act 'step-delete-back)
653             (delete-region point (point))))
654        ;; ... ... ... ... ... ... ... ... ... ... ... ... ... electric ..
655        ((and (memq act (list 'e-slash))
656              (ti::char-in-list-case (preceding-char) e-list)
657              ;; permit `//hostname/path/to/file'
658              (not (eq (point) (1+ (point-min))))
659              ;; permit `http://url/goes/here'
660              (not (char= ?: (char-after (- (point) 2)))))
661         (delete-region point (point))
662         (insert char))
663
664        ((memq act '(e-tilde))
665         (cond
666          ((char= (preceding-char) ?~)
667           ;;  /ftp@some:~  pressing "~" now deletes full line
668           (delete-region bolp (point)))
669          ((and (not (ti::win32-p)) (char= (preceding-char) ?:))
670           ;;  In NT, it's best to delete immediately, because you have
671           ;;  those MS-DOS filename C:/ ...
672           ;;
673           ;;  In Unix:
674           ;;  /ftp@some:   allow adding "~"
675           nil)
676          ((let ((filename (buffer-substring bolp (point))))
677             (if (not (string= (file-name-nondirectory filename) ""))
678                 ;;  find file which would have tilde in the name.
679                 (file-name-completion (file-name-nondirectory filename)
680                                       (file-name-directory filename))))
681           ;; skip electric: tilde is part of an existing filename
682           nil)
683          (t
684           (delete-region point (point))
685           (if (save-excursion (beginning-of-line) (looking-at "[a-z]:[/\\]?"))
686               ;;  Kill MS-DOS fabsolute path c:/this/dir
687               (delete-region (line-beginning-position) (point))
688             (delete-region point (point)))))
689         (insert char))
690        ((memq act '(e-dollar))
691         (delete-region bolp (point))
692         (insert char))
693        (t
694         (insert char))))))
695
696 ;;}}}
697
698 (tinyef-install)
699 (provide 'tinyef)
700
701 (run-hooks 'tinyef-:load-hook)
702
703 ;;; tinyef.el ends here