From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs-Devel <emacs-devel@gnu.org>
Subject: Re: display-completion-list should not strip text properties
Date: Mon, 22 Jan 2007 13:56:51 -0500 [thread overview]
Message-ID: <jwvwt3ec2pg.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <BDEIJAFNGDOAGCJIPKPBOEBKCCAA.drew.adams@oracle.com> (Drew Adams's message of "Mon\, 22 Jan 2007 09\:23\:10 -0800")
> Also, I haven't yet done so for my own Lisp version, but I think that the
> measures 35 and 45 for the column width, which are currently hard-coded,
> could usefully be made into either parameters to the function or global
> variables. Different uses of a completion display might call for different
> column widths, and I see no reason to hard-code this choice.
For what it's worth I use the code below (part of some other lib, so it
wouldn't surprise me if it doesn't work as-is).
It chooses the number of columns based on how many can fit.
Stefan
(defun complete-insert-strings (strings)
"Insert a list of STRINGS into the current buffer.
Uses columns to keep the listing readable but compact.
It also eliminates runs of equal strings."
(when (consp strings)
(let* ((length (apply 'max
(mapcar (lambda (s)
(if (consp s)
(+ (length (car s)) (length (cadr s)))
(length s)))
strings)))
(window (get-buffer-window (current-buffer)))
(wwidth (if window (1- (window-width window)) 79))
(columns (min
;; At least 2 columns; at least 2 spaces between columns.
(max 2 (/ wwidth (+ 2 length)))
;; Don't allocate more columns than we can fill.
;; Windows can't show less than 3 lines anyway.
(max 1 (/ (length strings) 2))))
(colwidth (/ wwidth columns))
(laststring nil))
;; Use tab-width rather than indent-to.
(setq tab-width colwidth)
;; The insertion should be "sensible" no matter what choices were made
;; for the parameters above.
(dolist (str strings)
(unless (equal laststring str)
(setq laststring str)
(unless (bolp) (insert " \t"))
(when (< wwidth (+ (max colwidth
(if (consp str)
(+ (length (car str)) (length (cadr str)))
(length str)))
(current-column)))
(delete-char -2) (insert "\n"))
(if (not (consp str))
(put-text-property (point) (progn (insert str) (point))
'mouse-face 'highlight)
(put-text-property (point) (progn (insert (car str)) (point))
'mouse-face 'highlight)
(set-text-properties (point) (progn (insert (cadr str)) (point))
nil)))))))
(defvar completion-common-substring)
(defun display-completion-list (completions &optional common-substring)
"Display the list of completions, COMPLETIONS, using `standard-output'.
Each element may be just a symbol or string
or may be a list of two strings to be printed as if concatenated.
`standard-output' must be a buffer.
The actual completion alternatives, as inserted, are given `mouse-face'
properties of `highlight'.
At the end, this runs the normal hook `completion-setup-hook'.
It can find the completion buffer in `standard-output'."
(if (not (bufferp standard-output))
;; This *never* (ever) happens, so there's no point trying to be clever.
(with-temp-buffer
(let ((standard-output (current-buffer))
(completion-setup-hook nil))
(display-completion-list completions))
(princ (buffer-string)))
(completion-setup-function) ;in simple.el
(with-current-buffer standard-output
(goto-char (point-max))
(if (null completions)
(insert "There are no possible completions of what you have typed.")
(insert "Possible completions are:\n")
(complete-insert-strings completions))))
(let ((completion-common-substring common-substring))
(run-hooks 'completion-setup-hook))
nil)
next prev parent reply other threads:[~2007-01-22 18:56 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-22 17:23 display-completion-list should not strip text properties Drew Adams
2007-01-22 18:56 ` Stefan Monnier [this message]
2007-01-23 2:07 ` Richard Stallman
2007-01-23 5:10 ` Drew Adams
2007-01-23 21:32 ` Drew Adams
2007-01-24 8:22 ` Richard Stallman
2007-01-24 23:43 ` Johan Bockgård
2007-01-25 10:53 ` Richard Stallman
2007-01-26 13:17 ` Vinicius Jose Latorre
2007-01-27 0:46 ` Richard Stallman
2007-09-01 19:56 ` Drew Adams
2007-09-02 18:52 ` Juri Linkov
2007-09-03 18:25 ` Richard Stallman
2007-09-03 23:48 ` Juri Linkov
2007-09-04 5:59 ` David Kastrup
2007-09-04 9:52 ` Juri Linkov
2007-09-04 8:49 ` tomas
2007-09-04 9:54 ` Juri Linkov
2007-09-04 10:56 ` Johan Bockgård
2007-09-04 22:58 ` Richard Stallman
2007-09-04 16:45 ` Richard Stallman
2007-09-04 18:51 ` Drew Adams
2007-09-04 22:46 ` Davis Herring
2007-09-05 6:16 ` Richard Stallman
2007-09-05 14:21 ` Drew Adams
2007-09-06 4:59 ` Richard Stallman
2007-09-06 16:35 ` Drew Adams
2007-09-06 20:04 ` Edward O'Connor
2007-09-06 20:16 ` Drew Adams
2007-09-06 23:08 ` Robert J. Chassell
2007-09-06 23:42 ` Davis Herring
2007-09-07 12:30 ` Robert J. Chassell
2007-09-08 7:00 ` Richard Stallman
2007-09-07 19:53 ` Richard Stallman
2007-09-07 22:07 ` Drew Adams
2007-09-06 20:06 ` David Kastrup
2007-09-06 20:22 ` Drew Adams
2007-09-07 6:31 ` Richard Stallman
2007-09-05 6:16 ` Richard Stallman
2007-03-20 22:36 ` Drew Adams
2007-04-02 16:55 ` Drew Adams
2007-04-02 18:51 ` Kim F. Storm
2007-04-03 21:40 ` Richard Stallman
2007-04-03 21:53 ` Juanma Barranquero
2007-04-04 14:03 ` Richard Stallman
2007-04-03 22:03 ` Nick Roberts
2007-04-04 14:03 ` Richard Stallman
2007-04-04 14:59 ` Chong Yidong
2007-04-05 23:11 ` Richard Stallman
2007-04-05 23:20 ` Chong Yidong
2007-04-06 19:47 ` Richard Stallman
2007-04-05 23:45 ` Nick Roberts
2007-04-06 1:15 ` Glenn Morris
2007-04-06 1:59 ` Chong Yidong
2007-04-06 2:22 ` David Kastrup
2007-04-06 4:18 ` Glenn Morris
2007-04-06 8:41 ` Eli Zaretskii
2007-04-06 14:47 ` Chong Yidong
2007-04-06 16:26 ` Kim F. Storm
2007-04-06 17:34 ` Eli Zaretskii
2007-04-07 12:40 ` Richard Stallman
2007-04-06 17:06 ` Kim F. Storm
2007-04-06 19:23 ` Kevin Rodgers changes Chong Yidong
2007-04-07 7:32 ` martin rudalics
2007-04-07 12:40 ` Richard Stallman
2007-04-07 16:57 ` Chong Yidong
2007-04-07 17:34 ` Eli Zaretskii
2007-04-08 12:28 ` Richard Stallman
2007-04-08 21:07 ` Eli Zaretskii
2007-04-09 14:33 ` Daniel Brockman
2007-04-09 15:42 ` Richard Stallman
2007-04-08 21:30 ` Chong Yidong
2007-04-09 15:42 ` Richard Stallman
2007-04-11 16:38 ` display-completion-list should not strip text properties Markus Triska
2007-04-11 17:13 ` Chong Yidong
2007-04-06 19:47 ` Richard Stallman
2007-04-06 8:42 ` Eli Zaretskii
2007-04-06 19:47 ` Richard Stallman
2007-04-04 17:45 ` Edward O'Connor
2007-04-05 14:36 ` Chong Yidong
2007-04-05 15:02 ` Juanma Barranquero
2007-04-05 23:11 ` Richard Stallman
2007-01-24 7:07 ` Kevin Rodgers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvwt3ec2pg.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).