unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Stefan Monnier'" <monnier@iro.umontreal.ca>
Cc: bug-gnu-emacs@gnu.org, 4835@emacsbugs.donarmstrong.com
Subject: bug#4835: 23.1; Improper `Invalid face reference' messages. Performance degraded.
Date: Sat, 31 Oct 2009 00:41:12 -0700	[thread overview]
Message-ID: <EDFBADBDF2B446CDA772DA010D5C5219@us.oracle.com> (raw)
In-Reply-To: <jwvbpjop7nl.fsf-monnier+emacsbugreports@gnu.org>

> > This sure seems like a bug to me. If not, please tell me what the
> > problem is.
> 
> The problem is that font-lock-keywords's docstring says:
> 
>    where MATCHER can be either the regexp to search for, or 
>    the function name to call to make the search (called with
>    one argument, the limit
> 
> notice that it says "function name" rather than just 
> "function".  So it can't just be a lambda expression, it has
> to be a symbol.


Ah, thank you. I need to put my reading glasses on!

1. However, the Elisp manual, node `Search-based Fontification' speaks of just
`function'. It does not say that it must be a symbol. (Also, the doc string
should be clarified, since "function name" is usually a string, the function
symbol's `symbol-name'.)

  `FUNCTION'
     Find text by calling FUNCTION, and highlight the matches it finds
     using `font-lock-keyword-face'.

     When FUNCTION is called, it receives one argument, the limit of
     the search; it should begin searching at point, and not search
     beyond the limit.  It should return non-`nil' if it succeeds, and
     set the match data to describe the match that was found.
     Returning `nil' indicates failure of the search.

     Fontification will call FUNCTION repeatedly with the same limit,
     and with point where the previous invocation left it, until
     FUNCTION fails.  On failure, FUNCTION need not reset point in any
     particular way.

And further references to it in this node also refer to it only as "a function".
Nowhere does it say that it should be a symbol. So if it must be a symbol, then
this is a doc bug.


2. The code I had seems nevertheless to "work", in the sense that it does what I
expect (highlights the column). Except that it logs those messages and the
performance is terrible. I assume that it is the message logging that degrades
the performance (brings Emacs to its knees).

Is it indeed a bug that binding `message-log-max' to nil does not suppress the
logging here? Or is it simply a doc bug that this limitation of
`message-log-max' is not mentioned?


3. I tried using a symbol, as you and the doc string suggested, but I still get
the same behavior. I used the same code as before, but with `column-marker-find'
redefined as follows, so that it now defines a named function and returns the
new function symbol:

(defun column-marker-find (col)
  (let ((fn-symb  (intern (format "column-marker-move-to-%d" col))))
    (fset
     `,fn-symb
     `(lambda (end)
        (let ((start (point)))
          (when (> end (point-max)) (setq end (point-max)))
          (unless (< (current-column) ,col) (forward-line 1))
          (when (< (current-column) ,col) (move-to-column ,col))
          (while (and (< (current-column) ,col) (< (point) end)
                      (= 0 (+ (forward-line 1) (current-column))))
            (move-to-column ,col))
          (if (and (= ,col (current-column))
                   (<= (point) end) (> (point) start))
              (progn (set-match-data (list (1- (point)) (point)))
                     t)
            (goto-char start)
            nil))))
    fn-symb))

Now I see only these 4 messages repeated over and over, instead of the messages
citing the atoms in the lambda form that I used previously:

Invalid face reference: t
Invalid face reference: prepend
Invalid face reference: 0
Invalid face reference: column-marker-move-to-36

`column-marker-move-to-36' is the symbol created when I did `M-x
column-marker-1'. Its `symbol-function' is this (same as above, with 36 for the
column):

(lambda (end)
  (let ((start (point)))
    (when (> end (point-max))
      (setq end (point-max)))
    (unless (< (current-column) 36)
      (forward-line 1))
    (when (< (current-column) 36)
      (move-to-column 36))
    (while (and (< (current-column) 36)
                (< (point) end)
                (= 0 (+ (forward-line 1)
                        (current-column))))
      (move-to-column 36))
    (if (and (= 36 (current-column))
             (<= (point) end)
             (> (point) start))
        (progn (set-match-data
                (list (1- (point)) (point)))
               t)
      (goto-char start)
      nil)))

The value of variable `column-marker-1' is now this list, which should be OK,
IIUC:

((column-marker-move-to-36
  (0 column-marker-1 prepend t)))

And that is therefore also the relevant portion of `font-lock-keywords'.

What am I missing?


4. Also, the full value of `font-lock-keywords' does in fact have lambda forms
in some of its keyword patterns, but they do not come from this code. They are
present even without it. This, for example:

((lambda (bound)
   (catch 'found
     (while
         (re-search-forward
"\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?:\\)?\\|[|)]\\)\\)" bound t)
       (unless (match-beginning 2)
         (let ((face (get-text-property (1- (point)) 'face)))
           (when (or (and (listp face)
                          (memq 'font-lock-string-face face))
                     (eq 'font-lock-string-face face))
             (throw 'found t)))))))
 (1 'font-lock-regexp-grouping-backslash prepend)
 (3 'font-lock-regexp-grouping-construct prepend))

Dunno where that comes from - perhaps from the font-lock machinery itself. In
any case, that lambda form does not seem to be causing any `Invalid face
reference' messages to be logged.


So I still don't understand, and I still haven't found the right way to code
this, so that I don't get the error messages. Please advise.






  reply	other threads:[~2009-10-31  7:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-30 22:48 bug#4835: 23.1; Improper `Invalid face reference' messages. Performance degraded Drew Adams
2009-10-31  3:26 ` Stefan Monnier
2009-10-31  7:41   ` Drew Adams [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-10-31 18:59 Chong Yidong
2009-10-31 19:09 ` Drew Adams
2009-10-31 19:37   ` Chong Yidong
2009-10-31 19:51     ` Drew Adams
2009-10-31 20:57       ` Chong Yidong
2009-10-31 21:10         ` Drew Adams
2009-10-31 22:05           ` Chong Yidong
2009-10-31 22:40             ` Drew Adams
2009-10-31 23:42               ` Chong Yidong
2009-11-01  0:04                 ` Drew Adams
2009-11-09 23:44                   ` Drew Adams
2009-12-09 18:23                     ` Drew Adams
2009-12-09 23:12                       ` bojohan+news
2009-12-10 17:36                         ` Drew Adams
2009-12-11  4:49                         ` Kevin Rodgers
2009-12-12  4:48                           ` Stefan Monnier
2016-04-27 20:20                       ` Lars Ingebrigtsen
2016-04-27 21:19                         ` Drew Adams

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=EDFBADBDF2B446CDA772DA010D5C5219@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=4835@emacsbugs.donarmstrong.com \
    --cc=bug-gnu-emacs@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).