From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: display-completion-list should not strip text properties Date: Mon, 22 Jan 2007 13:56:51 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1169492265 2905 80.91.229.12 (22 Jan 2007 18:57:45 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 22 Jan 2007 18:57:45 +0000 (UTC) Cc: Emacs-Devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 22 19:57:43 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1H94MI-0003kl-Fu for ged-emacs-devel@m.gmane.org; Mon, 22 Jan 2007 19:57:34 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H94MI-0004dY-4e for ged-emacs-devel@m.gmane.org; Mon, 22 Jan 2007 13:57:34 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H94Lc-0004DE-US for emacs-devel@gnu.org; Mon, 22 Jan 2007 13:56:52 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H94Lc-0004CD-2f for emacs-devel@gnu.org; Mon, 22 Jan 2007 13:56:52 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H94Lb-0004C5-Te for emacs-devel@gnu.org; Mon, 22 Jan 2007 13:56:51 -0500 Original-Received: from [209.226.175.110] (helo=tomts43-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.52) id 1H94Lb-00048x-HF for emacs-devel@gnu.org; Mon, 22 Jan 2007 13:56:51 -0500 Original-Received: from pastel.home ([74.12.211.125]) by tomts43-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20070122185650.SPRI11361.tomts43-srv.bellnexxia.net@pastel.home> for ; Mon, 22 Jan 2007 13:56:50 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 134346C579; Mon, 22 Jan 2007 13:56:51 -0500 (EST) Original-To: "Drew Adams" In-Reply-To: (Drew Adams's message of "Mon\, 22 Jan 2007 09\:23\:10 -0800") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.92 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:65384 Archived-At: > 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)