Commit 2da67aeb authored by David Byers's avatar David Byers
Browse files

Improved handling of initial input when reading conference names.

Detailed changes:
> 2003-08-15  David Byers  <byers@lysator.liu.se>
>
> 	* completing-read.el (lyskom-read-conf): Don't call
> 	lyskom-with-lyskom-minibuffer since it's integrated in
> 	lyskom-completing-read now.
> 	(lyskom-read-session-resolve-ambiguity): Same here.
>
> 	* lyskom-rest.el (lyskom-verified-read-from-minibuffer): Don't
> 	call lyskom-with-lyskom-minibuffer since it's integrated in
> 	lyskom-read-from-minibuffer now.
>
> 	* commands2.el (kom-calculate): Don't call
> 	lyskom-with-lyskom-minibuffer since it's integrated in
> 	lyskom-read-from-minibuffer now.
> 	(kom-set-personal-label): Same here.
>
> 	* command.el (lyskom-read-extended-command): Don't use
> 	lyskom-with-lyskom-minibuffer since it's integrated in
> 	lyskom-completing-read now.
>
> 	* utilities.el (lyskom-completing-read): Moved here from
> 	compatibility.el and turned into a regular function. Integrate
> 	lyskom-with-lyskom-minibuffer and lyskom-with-magic-minibuffer.
> 	(lyskom-read-from-minibuffer): Ditto.
>
> 	* commands1.el (kom-sub-self): Undo previous change. The new
> 	configuration mechanism takes care of things.
> 	(kom-go-to-conf): Same here.
>
> 	Even better defaults for initial conference:
> 	* compatibility.el (lyskom-completing-read): Use defsubst in Gnu
> 	Emacs so we can advise it.
>
> 	* vars.el.in (lyskom-default-conference-strategy): New variable.
>
> 	Rewrote magic minibuffer handling:
> 	* utilities.el (lyskom-magic-minibuffer-pre-command): New
> 	function.
> 	(lyskom-magic-minibuffer-before-change): New function.
> 	(lyskom-magic-minibuffer-post-command): New function.
> 	(lyskom-magic-minibuffer-cancel): New function.
> 	(lyskom-magic-minibuffer-mangle-initial): New function.
> 	(read-from-minibuffer): New advice.
> 	(completing-read): New advice.
> 	(lyskom-magic-minibuffer-add-advice): New function.
> 	(lyskom-magic-minibuffer-cancel-advice): New function.
> 	(lyskom-with-magic-minibuffer): New macro.
>
parent 9046fb8b
2003-08-15 David Byers <byers@lysator.liu.se>
* completing-read.el (lyskom-read-conf): Don't call
lyskom-with-lyskom-minibuffer since it's integrated in
lyskom-completing-read now.
(lyskom-read-session-resolve-ambiguity): Same here.
* lyskom-rest.el (lyskom-verified-read-from-minibuffer): Don't
call lyskom-with-lyskom-minibuffer since it's integrated in
lyskom-read-from-minibuffer now.
* commands2.el (kom-calculate): Don't call
lyskom-with-lyskom-minibuffer since it's integrated in
lyskom-read-from-minibuffer now.
(kom-set-personal-label): Same here.
* command.el (lyskom-read-extended-command): Don't use
lyskom-with-lyskom-minibuffer since it's integrated in
lyskom-completing-read now.
* utilities.el (lyskom-completing-read): Moved here from
compatibility.el and turned into a regular function. Integrate
lyskom-with-lyskom-minibuffer and lyskom-with-magic-minibuffer.
(lyskom-read-from-minibuffer): Ditto.
* commands1.el (kom-sub-self): Undo previous change. The new
configuration mechanism takes care of things.
(kom-go-to-conf): Same here.
Even better defaults for initial conference:
* compatibility.el (lyskom-completing-read): Use defsubst in Gnu
Emacs so we can advise it.
* vars.el.in (lyskom-default-conference-strategy): New variable.
Rewrote magic minibuffer handling:
* utilities.el (lyskom-magic-minibuffer-pre-command): New
function.
(lyskom-magic-minibuffer-before-change): New function.
(lyskom-magic-minibuffer-post-command): New function.
(lyskom-magic-minibuffer-cancel): New function.
(lyskom-magic-minibuffer-mangle-initial): New function.
(read-from-minibuffer): New advice.
(completing-read): New advice.
(lyskom-magic-minibuffer-add-advice): New function.
(lyskom-magic-minibuffer-cancel-advice): New function.
(lyskom-with-magic-minibuffer): New macro.
2003-08-15 Ulrik Haugen <qha@lysator.liu.se> 2003-08-15 Ulrik Haugen <qha@lysator.liu.se>
* english-strings.el (local): Changed "what conference" -> "which * english-strings.el (local): Changed "what conference" -> "which
......
...@@ -247,19 +247,18 @@ ...@@ -247,19 +247,18 @@
lyskom-command-minibuffer-local-must-match-map)) lyskom-command-minibuffer-local-must-match-map))
(while (or (null name) (while (or (null name)
(string= "" name)) (string= "" name))
(lyskom-with-lyskom-minibuffer (setq name (lyskom-completing-read prompt
(setq name (lyskom-completing-read prompt 'lyskom-complete-command
'lyskom-complete-command ;; lyskom-is-administrator is buffer-local and
;; lyskom-is-administrator is buffer-local and ;; must be evalled before the call to
;; must be evalled before the call to ;; completing-read
;; completing-read ;; Yes, this is not beautiful
;; Yes, this is not beautiful (list 'lambda '(alternative) ;
(list 'lambda '(alternative) ; (list 'lyskom-ok-command 'alternative
(list 'lyskom-ok-command 'alternative lyskom-is-administrator))
lyskom-is-administrator)) t
t nil
nil 'lyskom-command-history))))
'lyskom-command-history)))))
(cdr (lyskom-string-assoc name alternatives)))) (cdr (lyskom-string-assoc name alternatives))))
......
...@@ -899,13 +899,8 @@ See `kom-unsubscribe-makes-passive'." ...@@ -899,13 +899,8 @@ See `kom-unsubscribe-makes-passive'."
(interactive) (interactive)
(let* ((me (blocking-do 'get-conf-stat lyskom-pers-no)) (let* ((me (blocking-do 'get-conf-stat lyskom-pers-no))
(conf (if conf-no (blocking-do 'get-conf-stat conf-no) (conf (if conf-no (blocking-do 'get-conf-stat conf-no)
(let ((default (lyskom-read-conf-guess-initial '(membership))) (lyskom-read-conf-stat (lyskom-get-string 'leave-what-conf)
(mailbox (conf-stat->name me))) '(membership) nil nil t))))
(if (equal default mailbox)
(setq default ""))
(lyskom-read-conf-stat
(lyskom-get-string 'leave-what-conf)
'(membership) nil default t)))))
(lyskom-sub-member me conf))) (lyskom-sub-member me conf)))
(defun lyskom-sub-member (pers conf &optional have-message) (defun lyskom-sub-member (pers conf &optional have-message)
...@@ -1710,16 +1705,8 @@ Changing conferences runs `kom-change-conf-hook' and ...@@ -1710,16 +1705,8 @@ Changing conferences runs `kom-change-conf-hook' and
(interactive) (interactive)
(let ((conf (if conf-no (let ((conf (if conf-no
(blocking-do 'get-conf-stat conf-no) (blocking-do 'get-conf-stat conf-no)
(let ((default (lyskom-read-conf-guess-initial '(all))) (lyskom-read-conf-stat (lyskom-get-string 'go-to-conf-p)
(current (uconf-stat->name '(all) nil nil t))))
(blocking-do 'get-uconf-stat
lyskom-current-conf))))
(if (or (null current)
(equal default current))
(setq default ""))
(lyskom-read-conf-stat
(lyskom-get-string 'go-to-conf-p)
'(all) nil default t)))))
(when (lyskom-check-go-to-conf conf) (when (lyskom-check-go-to-conf conf)
(lyskom-go-to-conf conf)))) (lyskom-go-to-conf conf))))
......
...@@ -2248,10 +2248,9 @@ really only a simple interface to the basic functionality of calc." ...@@ -2248,10 +2248,9 @@ really only a simple interface to the basic functionality of calc."
(when (lyskom-try-require 'calc (when (lyskom-try-require 'calc
(lyskom-get-string 'need-library)) (lyskom-get-string 'need-library))
(let* ((expr (or exprx (let* ((expr (or exprx
(lyskom-with-lyskom-minibuffer (lyskom-read-from-minibuffer
(lyskom-read-from-minibuffer (lyskom-get-string 'calc-expression)
(lyskom-get-string 'calc-expression) nil nil nil 'lyskom-expression-history)))
nil nil nil 'lyskom-expression-history))))
(result (calc-eval expr))) (result (calc-eval expr)))
(cond ((stringp result) (cond ((stringp result)
(lyskom-format-insert-before-prompt (lyskom-format-insert-before-prompt
...@@ -2293,9 +2292,8 @@ Sets a personal label on an object of some kind." ...@@ -2293,9 +2292,8 @@ Sets a personal label on an object of some kind."
(setq secret (not (lyskom-j-or-n-p (setq secret (not (lyskom-j-or-n-p
(lyskom-get-string 'label-secret)))) (lyskom-get-string 'label-secret))))
(setq label (setq label
(lyskom-with-lyskom-minibuffer
(lyskom-read-from-minibuffer (lyskom-read-from-minibuffer
(lyskom-get-string 'label-what-label)))) (lyskom-get-string 'label-what-label)))
(blocking-do (blocking-do
'modify-text-info 'modify-text-info
objno objno
...@@ -2322,9 +2320,8 @@ Sets a personal label on an object of some kind." ...@@ -2322,9 +2320,8 @@ Sets a personal label on an object of some kind."
(setq secret (not (lyskom-j-or-n-p (setq secret (not (lyskom-j-or-n-p
(lyskom-get-string 'label-secret)))) (lyskom-get-string 'label-secret))))
(setq label (setq label
(lyskom-with-lyskom-minibuffer (lyskom-read-from-minibuffer
(lyskom-read-from-minibuffer (lyskom-get-string 'label-what-label)))
(lyskom-get-string 'label-what-label))))
(blocking-do (blocking-do
'modify-conf-info 'modify-conf-info
objno objno
......
...@@ -384,46 +384,6 @@ string to search in." ...@@ -384,46 +384,6 @@ string to search in."
(t (string-width str)))))) (t (string-width str))))))
(eval-and-compile
(cond ((eval-when-compile (string-match "XEmacs" (emacs-version)))
(defun lyskom-completing-read (prompt
table
&optional predicate require-match
init hist def inherit-input-method)
(completing-read prompt table predicate require-match init hist)))
((eval-when-compile (> emacs-major-version 19))
(fset 'lyskom-completing-read (symbol-function 'completing-read)))
(t
(defun lyskom-completing-read (prompt
table
&optional predicate require-match
init hist def inherit-input-method)
(completing-read prompt table predicate require-match init hist)))))
(eval-and-compile
(cond ((eval-when-compile (string-match "XEmacs" (emacs-version)))
(defun lyskom-read-from-minibuffer (prompt
&optional initial-contents
keymap read hist default-value
inherit-input-method)
(read-from-minibuffer prompt
initial-contents
keymap
read
hist)))
((eval-when-compile (> emacs-major-version 19))
(fset 'lyskom-read-from-minibuffer
(symbol-function 'read-from-minibuffer)))
(t (defun lyskom-read-from-minibuffer (prompt
&optional initial-contents
keymap read hist default-value
inherit-input-method)
(read-from-minibuffer prompt
initial-contents
keymap
read
hist)))))
(if (fboundp 'minibuffer-contents) (if (fboundp 'minibuffer-contents)
(defalias 'lyskom-minibuffer-contents 'minibuffer-contents) (defalias 'lyskom-minibuffer-contents 'minibuffer-contents)
(defalias 'lyskom-minibuffer-contents 'buffer-string)) (defalias 'lyskom-minibuffer-contents 'buffer-string))
......
...@@ -115,35 +115,6 @@ but first checks a cache." ...@@ -115,35 +115,6 @@ but first checks a cache."
map) map)
"Keymap used for reading LysKOM names.") "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)
(tmp nil)
(start (point-min)))
(while (setq tmp (lyskom-next-property-bounds
start (point-max) 'lyskom-initial-mbc))
(setq ranges (cons tmp ranges)
start (cdr tmp)))
(lyskom-traverse range ranges
(delete-region (car range) (cdr range)))
(when ranges
(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) (defsubst lyskom-completing-match-string-regexp (string)
...@@ -212,21 +183,54 @@ See lyskom-read-conf for a description of the parameters." ...@@ -212,21 +183,54 @@ See lyskom-read-conf for a description of the parameters."
(t (conf-z-info->name conf-z-info))))) (t (conf-z-info->name conf-z-info)))))
;;; ================================================================
;;; Code to guess defaults for initial input
;;;
(defun lyskom-default-conference-at-point ()
(let* ((pos (or lyskom-command-point (point)))
(type (and pos (get-text-property pos 'lyskom-button-type))))
(and (memq type '(conf pers))
(list (get-text-property pos 'lyskom-button-arg)))))
(defun lyskom-default-conference-current ()
(list lyskom-current-conf))
(defun lyskom-default-conference-self ()
(list lyskom-pers-no))
(defun lyskom-default-conference-not-self (uc)
(not (eq (uconf-stat->conf-no uc) lyskom-pers-no)))
(defun lyskom-default-conference-not-current (uc)
(not (eq (uconf-stat->conf-no uc) lyskom-current-conf)))
(defun lyskom-get-initial-conf-strategy ()
(or (cdr (assq lyskom-current-command lyskom-default-conference-strategy))
(cdr (assq t lyskom-default-conference-strategy))))
(defun lyskom-read-conf-guess-initial (predicate) (defun lyskom-read-conf-guess-initial (predicate)
"Return a guess for the initial value for lyskom-read-conf." "Return a guess for the initial value for lyskom-read-conf."
(let* ((pos (or lyskom-command-point (point))) (let* ((strategy (lyskom-get-initial-conf-strategy))
(type (and pos (get-text-property pos 'lyskom-button-type))) (default (cdr (assq 'default strategy)))
(conf-nos (delq nil (filter (cdr (assq 'filter strategy))))
(list (and (memq type '(conf pers))
(get-text-property pos 'lyskom-button-arg)) (uconf-stat->name
lyskom-current-conf (car (filter-list (lambda (uconf-stat)
lyskom-pers-no)))) (and uconf-stat
(lyskom-traverse conf-no conf-nos (not (memq nil (mapcar (lambda (fn)
(let ((uc (blocking-do 'get-uconf-stat conf-no))) (funcall fn uconf-stat))
(when (lyskom-read-conf-internal-verify-type filter)))
conf-no (uconf-stat->conf-type uc) (lyskom-read-conf-internal-verify-type
predicate nil nil) (uconf-stat->conf-no uconf-stat)
(lyskom-traverse-break (uconf-stat->name uc))))))) (uconf-stat->conf-type uconf-stat)
predicate nil nil)))
(mapcar (lambda (conf-no)
(blocking-do 'get-uconf-stat conf-no))
(apply 'append (mapcar 'funcall default))))))))
(defun lyskom-read-conf (prompt type &optional empty initial mustmatch) (defun lyskom-read-conf (prompt type &optional empty initial mustmatch)
"Completing read a conference or person from the minibuffer. "Completing read a conference or person from the minibuffer.
...@@ -268,22 +272,8 @@ A string: A name that matched nothing in the database." ...@@ -268,22 +272,8 @@ A string: A name that matched nothing in the database."
(conf-z-info->name initial)) (conf-z-info->name initial))
((consp initial) initial) ((consp initial) initial)
((lyskom-read-conf-guess-initial type)) ((lyskom-read-conf-guess-initial type))
((and lyskom-current-conf
(not (eq lyskom-current-conf 0)))
(uconf-stat->name
(blocking-do 'get-uconf-stat lyskom-current-conf)))
(t nil))) (t nil)))
(cond ((stringp initial)
(setq initial (copy-sequence initial))
(add-text-properties 0 (length initial)
'(lyskom-initial-mbc t) initial))
(initial
(setq initial (cons (copy-sequence (car initial)) (cdr initial)))
(add-text-properties 0 (length (car initial))
'(lyskom-initial-mbc t) (car initial))))
(let* ((completion-ignore-case t) (let* ((completion-ignore-case t)
(minibuffer-local-completion-map (minibuffer-local-completion-map
lyskom-minibuffer-local-completion-map) lyskom-minibuffer-local-completion-map)
...@@ -294,33 +284,16 @@ A string: A name that matched nothing in the database." ...@@ -294,33 +284,16 @@ A string: A name that matched nothing in the database."
(keep-going t)) (keep-going t))
(while keep-going (while keep-going
(lyskom-with-lyskom-minibuffer (setq read-string (lyskom-completing-read (cond ((stringp prompt) prompt)
(let ((before-change-functions before-change-functions) ((symbolp prompt) (lyskom-get-string prompt))
(pre-command-hook pre-command-hook) (t (lyskom-get-string 'conf-prompt)))
(post-command-hook post-command-hook) 'lyskom-read-conf-internal
(lyskom-minibuffer-point nil) type
(minibuffer-setup-hook mustmatch
(cons (lambda () (if (listp initial)
(setq before-change-functions initial
(cons 'lyskom-read-from-minibuffer-clear-initial (cons initial 0))
before-change-functions) 'lyskom-name-hist))
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))
(minibuffer-exit-hook
(cons 'lyskom-read-from-minibuffer-cancel-magic
minibuffer-exit-hook)))
(setq read-string (completing-read (cond ((stringp prompt) prompt)
((symbolp prompt) (lyskom-get-string prompt))
(t (lyskom-get-string 'conf-prompt)))
'lyskom-read-conf-internal
type
mustmatch
(if (listp initial)
initial
(cons initial 0))
'lyskom-name-hist))))
(setq result (setq result
(cond ((null read-string) nil) (cond ((null read-string) nil)
((string= "" read-string) nil) ((string= "" read-string) nil)
...@@ -1114,15 +1087,14 @@ the LysKOM rules of string matching." ...@@ -1114,15 +1087,14 @@ the LysKOM rules of string matching."
(lyskom-insert (lyskom-format 'total-users-sans-date (length who-info))) (lyskom-insert (lyskom-format 'total-users-sans-date (length who-info)))
(lyskom-scroll) (lyskom-scroll)
(while (string= "" (while (string= ""
(lyskom-with-lyskom-minibuffer (setq result (lyskom-completing-read
(setq result (lyskom-completing-read
(lyskom-get-string 'resolve-session) (lyskom-get-string 'resolve-session)
(lyskom-maybe-frob-completion-table (lyskom-maybe-frob-completion-table
who-info) who-info)
nil nil
t t
(car (car who-info)) (car (car who-info))
nil))))) nil))))
(list (session-info->connection (cdr (assoc result who-info))))))) (list (session-info->connection (cdr (assoc result who-info)))))))
......
...@@ -439,7 +439,7 @@ If NEWLINE is non-nil, insert a newline after the header." ...@@ -439,7 +439,7 @@ If NEWLINE is non-nil, insert a newline after the header."
(1- (length filter-edit-currently-edited-filter-entry-list))))) (1- (length filter-edit-currently-edited-filter-entry-list)))))
(insert "\n")) (insert "\n"))
(goto-char filter-edit-list-end)) (goto-char filter-edit-list-end))
(setq action (lyskom-completing-read (lyskom-get-string 'filter-edit-filter-how) (setq action (lyskom-completing-read (lyskom-get-string 'filter-edit-filter-how)
(lyskom-maybe-frob-completion-table (lyskom-maybe-frob-completion-table
rev-actions) rev-actions)
......
...@@ -3489,8 +3489,7 @@ PRED is a predicate to check entered data. It should return nil or a string. If ...@@ -3489,8 +3489,7 @@ PRED is a predicate to check entered data. It should return nil or a string. If
it returns a string, the data is not valid and the string is used as an error it returns a string, the data is not valid and the string is used as an error
message." message."
(let ((lyskom-verified-read-predicate pred)) (let ((lyskom-verified-read-predicate pred))
(lyskom-with-lyskom-minibuffer (lyskom-read-from-minibuffer prompt initial lyskom-verified-read-map)))
(lyskom-read-from-minibuffer prompt initial lyskom-verified-read-map))))
(defun lyskom-read-num-range-or-date (low high prompt &optional initial empty default) (defun lyskom-read-num-range-or-date (low high prompt &optional initial empty default)
......
...@@ -2075,3 +2075,180 @@ reflects an override of the value by the value of TAG." ...@@ -2075,3 +2075,180 @@ reflects an override of the value by the value of TAG."
(cdr (assq tag kom-extended-status-information))) (cdr (assq tag kom-extended-status-information)))
(t kom-extended-status-information))) (t kom-extended-status-information)))
;;; ============================================================
;;; Magic that allows us to clear the initial value in the
;;; minibuffer when the user types a character.
;;;
;;; We can't alter the buffer contents in before-change-functions
;;; since this can crash Gnu Emacs 20.7 (it computes positions
;;; internally before calling before-change-functions, and if
;;; those positions are invalid afterwards all sorts of things
;;; can happen).
;;;
;;; Theory of operation:
;;;
;;; In the pre-command-hook, record the position of point and
;;; the contents of the minibuffer.
;;;
;;; In before-change-functions, check if there is initial
;;; input in the buffer yet -- if not we're not yet ready
;;; to erase anything.
;;;
;;; In the post-command-hook, if the buffer contents have changed
;;; since there was inital input in the buffer, erase the initial
;;; input. If the position of point has moved, disable all the
;;; magic (both can happen at the same time).
;;;
;;; We set up advice on read-from-minibuffer and completing-read
;;; that mangles the initial input appropriately.
;;;
(defvar lyskom-minibuffer-point)
(defvar lyskom-minibuffer-string)
(defvar lyskom-minibuffer-do-change)
(defun lyskom-magic-minibuffer-pre-command (&rest args)
"Save current status of the minibuffer for later magic."
(setq lyskom-minibuffer-point (point)
lyskom-minibuffer-string (buffer-string)))
(defun lyskom-magic-minibuffer-before-change (&rest args)
"Check if the initial input has been placed in the minibuffer.
This function is called at least once before the initial input
has been placed in the minibuffer by Emacs. Most magic needs to
be disabled until the input has been deposited."
(setq lyskom-minibuffer-do-change
(lyskom-next-property-bounds (point-min)
(point-max) 'lyskom-initial-mbc)))
(defun lyskom-magic-minibuffer-post-command (&rest args)
"Function for use as post-command-hook in magic minibuffer.
If the contents of the minibuffer have changed since initial input
has been placed in the minibuffer, erase the initial input. This
happens when the user enters something in the minibuffer.
If point has moved, disable magic. This happens either after we
delete the initial contents (which is OK) or after the user moves
point without altering the buffer contents."
(when (and lyskom-minibuffer-do-change
(not (equal (buffer-string) lyskom-minibuffer-string)))
(let ((ranges nil)
(tmp nil)
(start (point-min)))
(while (setq tmp (lyskom-next-property-bounds
start (point-max) 'lyskom-initial-mbc))
(setq ranges (cons tmp ranges)
start (cdr tmp)))
(lyskom-traverse range ranges
(delete-region (car range) (cdr range)))
(when ranges
(lyskom-magic-minibuffer-cancel))))
(unless (or (null lyskom-minibuffer-point)
(eq lyskom-minibuffer-point (point)))
(lyskom-magic-minibuffer-cancel)))
(defun lyskom-magic-minibuffer-cancel ()
"Remove hooks used to make the minibuffer magic."
(remove-hook 'pre-command-hook 'lyskom-magic-minibuffer-pre-command)
(remove-hook 'post-command-hook 'lyskom-magic-minibuffer-post-command)
(remove-hook 'before-change-functions 'lyskom-magic-minibuffer-before-change))
(defun lyskom-magic-minibuffer-mangle-initial (initial)
"Add text properties to INITIAL (a string or cons) so it is
suitable for use as initial input in a magic minibuffer."
(cond ((null initial) nil)
((stringp initial)
(let ((tmp (copy-sequence initial)))
(add-text-properties 0 (length tmp) '(lyskom-initial-mbc t rear-nonsticky t end-open t) tmp)
tmp))
((consp initial)
(let ((tmp (copy-sequence (car initial))))
(add-text-properties 0 (length tmp) '(lyskom-initial-mbc t rear-nonsticky t end-open t) tmp)
(cons tmp (cdr initial))))
(t initial)))
;;; ------------------------------------------------------------
;;; Gnu Emacs and XEmacs have different names for parameters.
;;; This is stupid and makes the code below a lot uglier.
(defadvice read-from-minibuffer (around lyskom-magic-minibuffer-read-from-minibuffer nil disable)
(let* ((initial-input (and (boundp 'initial-input) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'initial-input))))
(initial-contents (and (boundp 'initial-contents) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'initial-contents))))
(initial (and (boundp 'initial) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'initial))))
(init (and (boundp 'init) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'init))))
(result ad-do-it))
(when (stringp result)
(remove-text-properties 0 (length result) '(end-open nil rear-nonsticky nil lyskom-initial-mbc nil) result)
(unless (or (text-properties-at 0 result)
(next-property-change 0 result))
(set-text-properties 0 (length result) nil result)))
result))
(defadvice completing-read (around lyskom-magic-minibuffer-completing-read nil disable)
(let* ((initial-input (and (boundp 'initial-input) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'initial-input))))
(initial-contents (and (boundp 'initial-contents) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'initial-contents))))
(initial (and (boundp 'initial) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'initial))))
(init (and (boundp 'init) (lyskom-magic-minibuffer-mangle-initial (symbol-value 'init))))
(result ad-do-it))
(when (stringp result)
(remove-text-properties 0 (length result) '(end-open nil rear-nonsticky nil lyskom-initial-mbc nil) result)
(unless (or (text-properties-at 0 result)