[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Gradually replacing INITIAL-INPUT in minibuffer
From: |
Arash Esbati |
Subject: |
Re: Gradually replacing INITIAL-INPUT in minibuffer |
Date: |
Thu, 24 Feb 2022 19:49:05 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 |
Hi all,
Tassilo Horn <tsdh@gnu.org> writes:
> Arash Esbati <arash@gnu.org> writes:
>
>> Before touching the rest, I like to discuss this here and hear from
>> users and developers what they think.
>
> Yes, please. :-)
This is my idea on this: We add an additional argument `default' to the
respective functions. Here an example for `TeX-arg-length':
--8<---------------cut here---------------start------------->8---
diff --git a/latex.el b/latex.el
index bfd5b8c6..549d4ca9 100644
--- a/latex.el
+++ b/latex.el
@@ -2222,25 +2222,32 @@ list of defined saveboxes."
(LaTeX-add-saveboxes savebox))
(TeX-argument-insert savebox optional TeX-esc)))
-(defun TeX-arg-length (optional &optional prompt initial-input definition)
+(defun TeX-arg-length (optional &optional prompt initial-input definition
default)
"Prompt for a LaTeX length.
If OPTIONAL is non-nil, insert the resulting value as an optional
argument, otherwise as a mandatory one. Use PROMPT as the prompt
string. If INITIAL-INPUT is non-nil, insert it in the minibuffer
initially, with point positioned at the end. If DEFINITION is
-non-nil, the length is added to the list of defined length."
- (let ((length (completing-read (TeX-argument-prompt optional prompt "Length")
- ;; A valid length can be a macro or a length
of
- ;; the form <value><dimension>. Input
starting
- ;; with a `\' can be completed with length
- ;; macros.
- (mapcar (lambda(elt) (concat TeX-esc (car
elt)))
- (LaTeX-length-list))
- ;; Some macros takes as argument only a length
- ;; macro (e.g., `\setlength' in its first
- ;; argument, and `\newlength'), in this case
is
- ;; convenient to set `\\' as initial input.
- nil nil initial-input)))
+non-nil, the length is added to the list of defined length.
+DEFAULT is passed to `completing-read', which see."
+ (let ((length (completing-read
+ (TeX-argument-prompt optional prompt
+ (if (and default (not optional))
+ (concat "Length (default "
+ default
+ ")")
+ "Length"))
+ ;; A valid length can be a macro or a length of
+ ;; the form <value><dimension>. Input starting
+ ;; with a `\' can be completed with length
+ ;; macros.
+ (mapcar (lambda(elt) (concat TeX-esc (car elt)))
+ (LaTeX-length-list))
+ ;; Some macros takes as argument only a length
+ ;; macro (e.g., `\setlength' in its first
+ ;; argument, and `\newlength'), in this case is
+ ;; convenient to set `\\' as initial input.
+ nil nil initial-input nil default)))
(if (and definition (not (zerop (length length))))
;; Strip leading TeX-esc from macro name
(LaTeX-add-lengths (substring length 1)))
--8<---------------cut here---------------end--------------->8---
The call in a style would change from
(TeX-arg-length "Width" "1.0\\linewidth")
to
(TeX-arg-length "Width" nil nil "1.0\\linewidth")
Note that the default value is considered only with a mandatory
argument.
One question: Is there a more elegant way to construct the prompt?
Any comments welcome.
Best, Arash