unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Leo <sdl.web@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 10062@debbugs.gnu.org
Subject: bug#10062: 24.0.91; completions-first-difference
Date: Mon, 16 Jan 2012 17:18:54 +0800	[thread overview]
Message-ID: <m1hazwc8e9.fsf@gmail.com> (raw)
In-Reply-To: <jwvk46ykxt7.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 17 Nov 2011 20:47:34 -0500")

[-- Attachment #1: Type: text/plain, Size: 984 bytes --]

On 2011-11-18 09:47 +0800, Stefan Monnier wrote:
[snipped 7 lines]
> Yup: the bug is not in the rear-stickiness but in the mere presence of
> this face.  I.e. the fix is to strip these faces when used for
> completion (but of course keep them when used for *Completions* display).
>
>
>         Stefan

On 2011-12-01 23:57 +0800, Stefan Monnier wrote:
[snipped 8 lines]
> I guess it could make sense to keep the face on the inserted text while
> you're still cycling, but it should be removed afterwards.  And since
> the transition between "cycling" and "not cycling" is not explicit,
> you'd then need/want to remove the face from something like
> a pre-command-hook.
>
>
>         Stefan

Hello Stefan,

I have been using completion with completion-cycle-threshold set to 4
and I have been annoyed often enough that I think it is worthwhile to
fix this bug because it often leaves my buffer weirdly fontified. For
example in elisp, `defma' can complete to `defmacro' unfontified.


[-- Attachment #2: emacs-comp-bug.png --]
[-- Type: image/png, Size: 7596 bytes --]

[-- Attachment #3: emacs-comp-correct.png --]
[-- Type: image/png, Size: 7782 bytes --]

[-- Attachment #4: Type: text/plain, Size: 133 bytes --]


I propose the attached patch following your advice i.e. strip faces when
used for completion. Could you take a look at it? Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: mb.diff --]
[-- Type: text/x-diff, Size: 4011 bytes --]

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2012-01-05 09:46:05 +0000
+++ lisp/minibuffer.el	2012-01-16 09:05:45 +0000
@@ -1180,6 +1180,9 @@
 of the differing parts is, by contrast, slightly highlighted."
   :group 'completion)
 
+(defvar completion-hilit-commonality-p nil
+  "Internal variable. Bound to t in `minibuffer-completion-help'.")
+
 (defun completion-hilit-commonality (completions prefix-len base-size)
   (when completions
     (let ((com-str-len (- prefix-len (or base-size 0))))
@@ -1195,17 +1198,18 @@
                      (car (setq elem (cons (copy-sequence (car elem))
                                            (cdr elem))))
                    (setq elem (copy-sequence elem)))))
-            (put-text-property 0
-			       ;; If completion-boundaries returns incorrect
-			       ;; values, all-completions may return strings
-			       ;; that don't contain the prefix.
-			       (min com-str-len (length str))
-                               'font-lock-face 'completions-common-part
-                               str)
-            (if (> (length str) com-str-len)
-                (put-text-property com-str-len (1+ com-str-len)
-                                   'font-lock-face 'completions-first-difference
-                                   str)))
+            (when completion-hilit-commonality-p
+              (put-text-property 0
+                                 ;; If completion-boundaries returns incorrect
+                                 ;; values, all-completions may return strings
+                                 ;; that don't contain the prefix.
+                                 (min com-str-len (length str))
+                                 'font-lock-face 'completions-common-part
+                                 str)
+              (if (> (length str) com-str-len)
+                  (put-text-property com-str-len (1+ com-str-len)
+                                     'font-lock-face 'completions-first-difference
+                                     str))))
           elem)
         completions)
        base-size))))
@@ -1314,12 +1318,13 @@
          (end (field-end))
          (string (field-string))
          (md (completion--field-metadata start))
-         (completions (completion-all-completions
-                       string
-                       minibuffer-completion-table
-                       minibuffer-completion-predicate
-                       (- (point) (field-beginning))
-                       md)))
+         (completions (let ((completion-hilit-commonality-p t))
+                        (completion-all-completions
+                         string
+                         minibuffer-completion-table
+                         minibuffer-completion-predicate
+                         (- (point) (field-beginning))
+                         md))))
     (message nil)
     (if (or (null completions)
             (and (not (consp (cdr completions)))
@@ -2411,14 +2416,15 @@
          (setq str (copy-sequence str))
          (unless (string-match re str)
            (error "Internal error: %s does not match %s" re str))
-         (let ((pos (or (match-beginning 1) (match-end 0))))
-           (put-text-property 0 pos
-                              'font-lock-face 'completions-common-part
-                              str)
-           (if (> (length str) pos)
-               (put-text-property pos (1+ pos)
-				  'font-lock-face 'completions-first-difference
-				  str)))
+         (when completion-hilit-commonality-p
+           (let ((pos (or (match-beginning 1) (match-end 0))))
+             (put-text-property 0 pos
+                                'font-lock-face 'completions-common-part
+                                str)
+             (if (> (length str) pos)
+                 (put-text-property pos (1+ pos)
+                                    'font-lock-face 'completions-first-difference
+                                    str))))
 	 str)
        completions))))
 


[-- Attachment #6: Type: text/plain, Size: 148 bytes --]


Another simpler fix is to replace 'font-lock-face with 'face which would
then allow the major-mode to override the faces added by completion.

Leo

  reply	other threads:[~2012-01-16  9:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-16  9:45 bug#10062: 24.0.91; completions-first-difference Leo
2011-11-17 16:25 ` Leo
2011-11-18  1:47   ` Stefan Monnier
2012-01-16  9:18     ` Leo [this message]
2012-01-16 15:52       ` Stefan Monnier
2012-01-17  4:29         ` Leo
2012-01-17 14:07           ` Stefan Monnier
2011-12-01  4:20   ` Leo
2011-12-01 15:57     ` Stefan Monnier

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=m1hazwc8e9.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=10062@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).