[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: face vs. mouse-face text property

From: Stefan Monnier
Subject: Re: face vs. mouse-face text property
Date: Mon, 23 Jan 2012 09:27:36 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

> Therefore, I think if we want to be able to display selectable
> newlines, we need to have a special way to display such newlines,
> e.g. "<NL>" or some such.

I'd suggest \n rather than <NL>, since it's already used at many other
places in Emacs (tho it's not often visible to the "end user").

There are other similar issues in the *Completions* lists if you have
completions which start/end with spaces or tabs, are very long, or worse
only contain spaces or tabs: while the mouse-over will be reasonably
clear, the list is far from clear if you don't move your mouse over it
to see the exact boundaries.

Currently, completions are used for entities which typically don't
suffer from such issues.  But if we want to use it for things like
yank-browse (see sample code below), we need to make it handle such
cases a bit better.


(defun yank-browse (string)
  "Browse the `kill-ring' to choose which entry to yank."
   (minibuffer-with-setup-hook #'minibuffer-completion-help
     (let* ((kills (delete-dups (append kill-ring-yank-pointer kill-ring nil)))
             (mapcar (lambda (string)
                       (let ((pos 0))
                         ;; FIXME: Maybe we should start by removing
                         ;; all properties.
                         (setq string (copy-sequence string))
                         (while (string-match "\n" string pos)
                           ;; FIXME: Maybe completion--insert-strings should
                           ;; do that for us.
                            (match-beginning 0) (match-end 0)
                            'display (eval-when-compile
                                       (propertize "\\n" 'face 'escape-glyph))
                           (setq pos (match-end 0)))
                         ;; FIXME: We may use the window-width of the
                         ;; wrong window.
                         (when (>= (* 3 (string-width string))
                                   (* 2 (window-width)))
                           (let ((half (- (/ (window-width) 3) 1)))
                             ;; FIXME: We're using char-counts rather than
                             ;; width-count.
                              half (- (length string) half)
                              'display (eval-when-compile
                                         (propertize "……" 'face 'escape-glyph))
            (table (lambda (string pred action)
                      ((eq action 'metadata)
                       '(metadata (category . kill-ring)))
                       (complete-with-action action entries string pred))))))
       ;; FIXME: We should return the entry from the kill-ring rather than
       ;; the entry from the completion-table.
       ;; FIXME: substring completion doesn't work well because it only matches
       ;; subtrings before the first \n.
       ;; FIXME: completion--insert-strings assumes that boundaries of
       ;; candidates are obvious enough, but with kill-ring entries this is not
       ;; true, so we'd probably want to display them with «...» around them.
       (list (completing-read "Yank: " table nil t)))))
  (setq this-command 'yank)
  (insert-for-yank string))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]