Commit ce295516 authored by David Byers's avatar David Byers
Browse files

Improved handling of initial value in minibuffer when reading confs.

Detailed changes:
>	Delete initial value on change:
>	* completing-read.el (lyskom-read-conf): Set pre-command-hook
>	and post-command-hook.
> 	(lyskom-read-from-minibuffer-cancel-magic): New function.
> 	(lyskom-read-from-minibuffer-pre-command): New funtion.
> 	(lyskom-read-from-minibuffer-post-command): New function.
> 	(lyskom-minibuffer-point): New variable.
parent 00ac77f8
......@@ -5,6 +5,11 @@
New function.
(lyskom-read-conf): Put it into before-change-functions in
minibuffer-setup-hook.
(lyskom-read-conf): Set pre-command-hook and post-command-hook.
(lyskom-read-from-minibuffer-cancel-magic): New function.
(lyskom-read-from-minibuffer-pre-command): New funtion.
(lyskom-read-from-minibuffer-post-command): New function.
(lyskom-minibuffer-point): New variable.
2003-08-12 David Byers <byers@lysator.liu.se>
......
......@@ -115,6 +115,8 @@ but first checks a cache."
map)
"Keymap used for reading LysKOM names.")
(defvar lyskom-minibuffer-point)
(defun lyskom-read-from-minibuffer-clear-initial (&rest args)
(condition-case nil
(let ((ranges nil)
......@@ -127,11 +129,23 @@ but first checks a cache."
(lyskom-traverse range ranges
(delete-region (car range) (cdr range)))
(when ranges
(setq before-change-functions
(delq 'lyskom-read-from-minibuffer-clear-initial
before-change-functions))))
(lyskom-read-from-minibuffer-cancel-magic)))
(error nil)))
(defun lyskom-read-from-minibuffer-cancel-magic ()
(setq pre-command-hook (delq 'lyskom-read-from-minibuffer-pre-command pre-command-hook)
post-command-hook (delq 'lyskom-read-from-minibuffer-post-command post-command-hook)
before-change-functions (delq 'lyskom-read-from-minibuffer-clear-initial before-change-functions)))
(defun lyskom-read-from-minibuffer-pre-command (&rest args)
(setq lyskom-minibuffer-point (point)))
(defun lyskom-read-from-minibuffer-post-command (&rest args)
(unless (or (null lyskom-minibuffer-point)
(eq lyskom-minibuffer-point (point)))
(lyskom-read-from-minibuffer-cancel-magic)))
(defsubst lyskom-completing-match-string-regexp (string)
(concat "^"
(replace-in-string (regexp-quote (lyskom-unicase (lyskom-completing-strip-name string)))
......@@ -282,11 +296,16 @@ A string: A name that matched nothing in the database."
(while keep-going
(lyskom-with-lyskom-minibuffer
(let ((before-change-functions before-change-functions)
(pre-command-hook pre-command-hook)
(post-command-hook post-command-hook)
(lyskom-minibuffer-point nil)
(minibuffer-setup-hook
(cons (lambda ()
(setq before-change-functions
(cons 'lyskom-read-from-minibuffer-clear-initial
before-change-functions)))
before-change-functions)
pre-command-hook (cons 'lyskom-read-from-minibuffer-pre-command pre-command-hook)
post-command-hook (cons 'lyskom-read-from-minibuffer-post-command post-command-hook)))
minibuffer-setup-hook)))
(setq read-string (completing-read (cond ((stringp prompt) prompt)
((symbolp prompt) (lyskom-get-string prompt))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment