all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#4835: 23.1; Improper `Invalid face reference' messages. Performance degraded.
@ 2009-10-31 18:59 Chong Yidong
  2009-10-31 19:09 ` Drew Adams
  0 siblings, 1 reply; 21+ messages in thread
From: Chong Yidong @ 2009-10-31 18:59 UTC (permalink / raw)
  To: Drew Adams; +Cc: 4835

> 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 suspect this is because parts of font-lock do this:

  (if (stringp matcher)
      (re-search-forward matcher end t)
   (funcall matcher end)))

while other parts do this:

  (font-lock-eval-keywords (if (fboundp keywords)
                               (funcall keywords)
                             (eval keywords)))))

If `matcher' is a lambda expression, the first will work as expected,
because you can pass a lambda to funcall.  But the second will do the
wrong thing.

We should probably fix the code to check for and disallow lambda
expressions (and the docs), assuming not too much external code is
relying on the unintended behavior.





^ permalink raw reply	[flat|nested] 21+ messages in thread
* bug#4835: 23.1; Improper `Invalid face reference' messages. Performance degraded.
@ 2009-10-30 22:48 Drew Adams
  2009-10-31  3:26 ` Stefan Monnier
  0 siblings, 1 reply; 21+ messages in thread
From: Drew Adams @ 2009-10-30 22:48 UTC (permalink / raw)
  To: bug-gnu-emacs

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

This sure seems like a bug to me. If not, please tell me what the
problem is.
 
Load the attached file, move point to, say, column 15 in some buffer
(e.g. *scratch*), then do `M-x column-marker-1'. Move point a bit, to
be sure to see the column highlighting.
 
Check buffer `*Messages*'. You will see zillions of messages `Invalid
face reference', logged by the C function `merge_face_ref' (in
`xfaces.c').  If you click the mouse in `*Messages*', zillions more
such messages will be displayed. This message logging degrades Emacs
performance considerably.
 
Also, binding `message-log-max' to nil has no effect - it does not
inhibit the message logging. That seems like a bug in itself.  But
perhaps you will say that this message is coming from the display
engine, and that it is appropriate for the display code to ignore
`message-log-max' (but why, especially if it impacts performance so
much?).  At the very least, there is a doc bug, since neither the
manual nor the doc string say anything about the display code ignoring
this variable.
 
Anyway, displaying the message at all seems like a bug in this case.
But if not, I would appreciate understanding what is wrong with the
code I'm using. In the attached code, `M-x column-marker-1' calls:
 
(column-marker-internal
  'column-marker-1
  (1+ (current-column)) 'column-marker-1)
 
That sets the value of symbol `column-marker-1' to the following list
- call it KEYWORDS, where COL is the column that point was in when you
did `M-x column-marker-1' (e.g. 15).
 
KEYWORDS:
 
(((lambda (end)
    (let ((start (point))
          (message-log-max nil)) ; (Has no effect.)
      (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)))
  (0 column-marker-1 prepend t)))
 
And then `column-marker-internal' calls this, where KEYWORDS is the
list shown above:
 
(font-lock-add-keywords nil KEYWORDS t)
(font-lock-fontify-buffer)
 
The effect is to highlight the column where you issued the command. It
works well, apart from the message logging and its performance impact.
 
The `font-lock-keywords' entry used has a lambda form as car and this
as cadr: (0 column-marker-1 prepend t). Face `column-marker-1' is
defined as follows:
 
(defface column-marker-1 '((t (:background "gray")))
  "Face used for a column marker.  Usually a background color."
  :group 'faces)
 
The lambda form is thus, AFAICT, just the kind of function that
`font-lock(-add)-keywords' expects. Please let me know if I'm missing
something.
 
I think I am correctly using the form (MATCHER HIGHLIGHTER...), from
node `Search-based Fontification' of the Elisp manual.
 
MATCHER here is the lambda form shown above. There is only one
HIGHLIGHTER, with form SUBEXP-HIGHLIGHTER. The SUBEXP-HIGHLIGHTER here
is of form (SUBEXP FACESPEC OVERRIDE LAXMATCH), with SUBEXP=0,
FACESPEC=the symbol (face name) `column-marker-1', OVERRIDE=`prepend',
and LAXMATCH=t.
 
I also tried removing the parens around (0 column-marker-1 prepend t),
making it the cdr instead of the cadr, so it looked like this:
(MATCHER 0 column-marker-1 prepend t), where MATCHER is the same
lambda form. That should match the also-allowed form (MATCHER
. SUBEXP-HIGHLIGHTER). But that didn't change anything.
 
What's odd is that the message complains about a _face reference_, but
the text included with the error message is code from the lambda form
(i.e. from the MATCHER part, not from the HIGHLIGHTER part that
specifies the face).  The display code seems to be walking down the
lambda form, spitting it out bit by bit progressively in the `Invalid
face reference' messages. E.g.:
 
Invalid face reference: end
Invalid face reference: point
Invalid face reference: <=
Invalid face reference: current-column
Invalid face reference: 37
Invalid face reference: =
Invalid face reference: and
Invalid face reference: if
Invalid face reference: 37
Invalid face reference: move-to-column
Invalid face reference: current-column
Invalid face reference: 1
Invalid face reference: forward-line
Invalid face reference: +
Invalid face reference: 0
Invalid face reference: =
Invalid face reference: end
Invalid face reference: point
Invalid face reference: <
Invalid face reference: 37
Invalid face reference: current-column
Invalid face reference: <
Invalid face reference: and
Invalid face reference: while
Invalid face reference: 37
Invalid face reference: move-to-column
Invalid face reference: 37
Invalid face reference: current-column
Invalid face reference: <
Invalid face reference: when
Invalid face reference: 1
Invalid face reference: forward-line
Invalid face reference: 37
Invalid face reference: current-column
Invalid face reference: <
Invalid face reference: unless
Invalid face reference: point-max
Invalid face reference: end
Invalid face reference: setq
Invalid face reference: point-max
Invalid face reference: end
Invalid face reference: >
Invalid face reference: when
Invalid face reference: nil
Invalid face reference: message-log-max
Invalid face reference: point
Invalid face reference: start
Invalid face reference: let
Invalid face reference: end
Invalid face reference: lambda
Invalid face reference: t
Invalid face reference: prepend
Invalid face reference: 0
Invalid face reference: nil
Invalid face reference: start
Invalid face reference: goto-char
Invalid face reference: t
Invalid face reference: point [2 times]
Invalid face reference: 1-
Invalid face reference: list
Invalid face reference: set-match-data
Invalid face reference: progn
Invalid face reference: start
Invalid face reference: point
Invalid face reference: >
Invalid face...
(repeated)
 
It's as if the code were trying to get face specs from the lambda
form, in order to merge those faces. Just a guess. At any rate, it
seems bugged to me, but if not, please let me know what I'm doing
wrong. Thx.
 

In GNU Emacs 23.1.1 (i386-mingw-nt5.1.2600)
 of 2009-07-29 on SOFT-MJASON
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.4)'
 

[-- Attachment #2: column-marker.el --]
[-- Type: application/octet-stream, Size: 10486 bytes --]

;;; column-marker.el --- Highlight certain character columns
;; 
;; Filename: column-marker.el
;; Description: Highlight certain character columns
;; Author: Rick Bielawski <rbielaws@i1.net>
;; Maintainer: Rick Bielawski <rbielaws@i1.net>
;; Created: Tue Nov 22 10:26:03 2005
;; Version: 
;; Last-Updated: Fri Oct 30 13:20:01 2009 (-0700)
;;           By: dradams
;;     Update #: 291
;; Keywords: tools convenience highlight
;; Compatibility: GNU Emacs 21, GNU Emacs 22
;; 
;; Features that might be required by this library:
;;
;;   None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Commentary: 
;; 
;; Highlights the background at a given character column.
;; 
;; Commands `column-marker-1', `column-marker-2', and
;; `column-marker-3' each highlight a given column (using different
;; background colors, by default).
;;
;; - With no prefix argument, each highlights the current column
;;   (where the cursor is).
;;
;; - With a non-negative numeric prefix argument, each highlights that
;;   column.
;;
;; - With plain `C-u' (no number), each turns off its highlighting.
;;
;; - With `C-u C-u', each turns off all column highlighting.
;;
;; If two commands highlight the same column, the last-issued
;; highlighting command shadows the other - only the last-issued
;; highlighting is seen.  If that "topmost" highlighting is then
;; turned off, the other highlighting for that column then shows
;; through.
;;
;; Examples:
;;
;; M-x column-marker-1 highlights the column where the cursor is, in
;; face `column-marker-1'.
;;
;; C-u 70 M-x column-marker-2 highlights column 70 in face
;; `column-marker-2'.
;;
;; C-u 70 M-x column-marker-3 highlights column 70 in face
;; `column-marker-3'.  The face `column-marker-2' highlighting no
;; longer shows.
;;
;; C-u M-x column-marker-3 turns off highlighting for column-marker-3,
;; so face `column-marker-2' highlighting shows again for column 70.
;;
;; C-u C-u M-x column-marker-1 (or -2 or -3) erases all column
;; highlighting.
;;
;; These commands use `font-lock-fontify-buffer', so syntax
;; highlighting (`font-lock-mode') must be turned on.  There might be
;; a performance impact during refontification.
;;
;;
;; Installation: Place this file on your load path, and put this in
;; your init file (`.emacs'):
;;
;; (require 'column-marker)
;;
;; Other init file suggestions (examples):
;;
;; ;; Highlight column 80 in foo mode.
;; (add-hook foo-mode-hook (lambda () (interactive) (column-marker-1 80)))
;;
;; ;; Use `C-c m' interactively to highlight with face `column-marker-1'.
;; (global-set-key [?\C-c ?m] 'column-marker-1)
;;
;;
;; Please report any bugs!
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Change log:
;;
;; 2008/01/21 dadams
;;     Renamed faces by dropping suffix "-face".
;; 2006/08/18 dadams
;;     column-marker-create: Add newlines to doc-string sentences.
;; 2005/12/31 dadams
;;     column-marker-create: Add marker to column-marker-vars inside the defun,
;;       so it is done in the right buffer, updating column-marker-vars buffer-locally.
;;     column-marker-find: Corrected comment.  Changed or to progn for clarity.
;; 2005/12/29 dadams
;;     Updated wrt new version of column-marker.el (multi-column characters).
;;     Corrected stray occurrences of column-marker-here to column-marker-1.
;;     column-marker-vars: Added make-local-variable.
;;     column-marker-create: Changed positive to non-negative.
;;     column-marker-internal: Turn off marker when col is negative, not < 1.
;; 2005-12-29 RGB
;;     column-marker.el now supports multi-column characters.
;; 2005/11/21 dadams
;;     Combined static and dynamic. 
;;     Use separate faces for each marker.  Different interactive spec.
;; 2005/10/19 RGB
;;     Initial release of column-marker.el.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Code:

;;;;;;;;;;;;;;;;;;;;;;


(defface column-marker-1 '((t (:background "gray")))
  "Face used for a column marker.  Usually a background color."
  :group 'faces)

(defvar column-marker-1-face 'column-marker-1
    "Face used for a column marker.  Usually a background color.
Changing this directly affects only new markers.")

(defface column-marker-2 '((t (:background "cyan3")))
  "Face used for a column marker.  Usually a background color."
  :group 'faces)

(defvar column-marker-2-face 'column-marker-2
    "Face used for a column marker.  Usually a background color.
Changing this directly affects only new markers." )

(defface column-marker-3 '((t (:background "orchid3")))
  "Face used for a column marker.  Usually a background color."
  :group 'faces)

(defvar column-marker-3-face 'column-marker-3
    "Face used for a column marker.  Usually a background color.
Changing this directly affects only new markers." )

(defvar column-marker-vars nil
  "List of all internal column-marker variables")
(make-variable-buffer-local 'column-marker-vars) ; Buffer local in all buffers.

(defmacro column-marker-create (var &optional face)
  "Define a column marker named %%colmark%%-VAR.
FACE is the face to use.  If nil, then face `column-marker-1' is used."
  (setq face (or face 'column-marker-1))
  `(progn
     ;; define context variable ,VAR so marker can be removed if desired
     (defvar ,var ()
       "Buffer local. Used internally to store column marker spec.")
     ;; context must be buffer local since font-lock is 
     (make-variable-buffer-local ',var)
     ;; Define wrapper function named ,VAR to call `column-marker-internal'
     (defun ,var (arg)
       ,(concat "Highlight column with face `" (symbol-name face)
                "'.\nWith no prefix argument, highlight current column.\n"
                "With non-negative numeric prefix arg, highlight that column number.\n"
                "With plain `C-u' (no number), turn off this column marker.\n"
                "With `C-u C-u' or negative prefix arg, turn off all column-marker highlighting.")
       (interactive "P")
       (unless (memq ',var column-marker-vars) (push ',var column-marker-vars))
       (cond ((null arg)          ; Default: highlight current column.
              (column-marker-internal ',var (1+ (current-column)) ,face))
             ((consp arg)
              (if (= 4 (car arg))
                  (column-marker-internal ',var nil) ; `C-u': Remove this column highlighting.
                (dolist (var column-marker-vars)
                  (column-marker-internal var nil)))) ; `C-u C-u': Remove all column highlighting.
             ((and (integerp arg) (>= arg 0)) ; `C-u 70': Highlight that column.
              (column-marker-internal ',var (1+ (prefix-numeric-value arg)) ,face))
             (t           ; `C-u -40': Remove all column highlighting.
              (dolist (var column-marker-vars)
                (column-marker-internal var nil)))))))

(defun column-marker-find (col)
  "Returns a function to locate a character in column COL."
  `(lambda (end)
    (let ((start            (point))
          (message-log-max  nil))
      (when (> end (point-max)) (setq end (point-max)))

      ;; Try to keep `move-to-column' from going backward, though it still can.
      (unless (< (current-column) ,col) (forward-line 1))

      ;; Again, don't go backward.  Try to move to correct column.
      (when (< (current-column) ,col) (move-to-column ,col))

      ;; If not at target column, try to move to it.
      (while (and (< (current-column) ,col) (< (point) end)
                  (= 0 (+ (forward-line 1) (current-column)))) ; Should be bol.
        (move-to-column ,col))

      ;; If at target column, not past end, and not prior to start,
      ;; then set match data and return t.  Otherwise go to start
      ;; and return nil.
      (if (and (= ,col (current-column)) (<= (point) end) (> (point) start))
          (progn (set-match-data (list (1- (point)) (point)))
                 t) ; Return t.
        (goto-char start)
        nil))))       ; Return nil.

(defun column-marker-internal (sym col &optional face)
  "SYM is the symbol for holding the column marker context.
COL is the column in which a marker should be set.
Supplying nil or 0 for COL turns off the marker.
FACE is the face to use.  If nil, then face `column-marker-1' is used."
  (setq face (or face 'column-marker-1))
  (when (symbol-value sym)   ; Remove any previously set column marker
    (font-lock-remove-keywords nil (symbol-value sym))
    (set sym nil))
  (when (or (listp col) (< col 0)) (setq col nil)) ; Allow nonsense stuff to turn off the marker
  (when col                             ; Generate a new column marker
    (set sym `((,(column-marker-find col) (0 ,face prepend t))))
    (font-lock-add-keywords nil (symbol-value sym) t))
  (font-lock-fontify-buffer))

;; If you need more markers you can create your own similarly.
;; All markers can be in use at once, and each is buffer-local,
;; so there is no good reason to define more unless you need more
;; markers in a single buffer.
(column-marker-create column-marker-1 column-marker-1-face)
(column-marker-create column-marker-2 column-marker-2-face)
(column-marker-create column-marker-3 column-marker-3-face)

;;;###autoload
(autoload 'column-marker-1 "column-marker" "Highlight a column." t)

;;;;;;;;;;;;;;;;;;

(provide 'column-marker)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; column-marker.el ends here

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-04-27 21:19 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-31 18:59 bug#4835: 23.1; Improper `Invalid face reference' messages. Performance degraded 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
  -- strict thread matches above, loose matches on Subject: below --
2009-10-30 22:48 Drew Adams
2009-10-31  3:26 ` Stefan Monnier
2009-10-31  7:41   ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.