Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In Emacs;

Is there a way for both window-display-table and buffer-display-table to have effect at the same time?

The reason is, I'm using Pretty-Control-L (from Emacs Goodies El script package) and whitespace (of whitespace.el, I think it is in the base Emacs distribution, but I’m not sure).

  • Pretty-Control-L visualizes form-feeds (^L) in a customized manner, by setting the entry for C-l in the window-local window-display-table.
  • Whitespace visualizes spaces, tabs and newlines by setting entries in the buffer-local buffer-display-table. (and also by using font-lock functionality).

These uses clashes (or rather, the use of a window-display-table and buffer-display-table clashes) since, if the window-display-table is non-nil it completely overrides any buffer-display-table for any buffer displayed in that window.

Quote from the Emacs Lisp manual:

38.21.2 Active Display Table

Each window can specify a display table, and so can each buffer. When a buffer B is displayed in window W, display uses the display table for window W if it has one; otherwise, the display table for buffer B if it has one; otherwise, the standard display table if any. The display table chosen is called the "active" display table.

[...]

(emphasis by me)

So, Is there any easy way to consolidate this? Or is the only way to re-code one of them to use the same mechanism as the other?

I've been considering writing a small (i.e. even smaller) crude variant of the form-feed visualization compatible with the white-space visualization that just uses some buffer-loading hook (or other) to put a hard-coded entry for ^L in the buffer-display-table. But I’d like to know if there’s any simpler alternative.


EDIT: To clarify the problem, here's a excerpt of an annotated "Interactive Lisp" session (i.e. from the *scratch*-buffer). This shows the commands and their output, and annotated with the effects:

;; Emacs is started with `-q', to not load my init-file(s).

;; First, write some sample text with tabs and line-feeds:

"A tab: and some text
A line-feed:and some text"
;; Make sure that it is a tab on the first line (input by `C-q TAB')
;; and a line-feed on the second line (input by `C-q C-l').
;; These probably wont copy properly into Stack Exchange.

;; This shows the spaces as center-dots, tabs as `>>'-glyphs and
;; new-lines as $'s (or perhaps other glyphs, depending on system
;; setup...). All of them fontified to be dimmed out on yellow/beige/white
;; background.
(whitespace-mode t)
t

;; This turns on pretty-control-l mode. The `^L' above will be
;; prettified...  Since this sets the window display table, the glyphs
;; for the spaces/tabs/new-lines will disappear, but the background of
;; spaces/tabs will still be yellow/beige (since that's done with
;; fontification, not display tables).
(pretty-control-l-mode t)
t

;; This turns pretty-control-l mode OFF again. The form-feed will
;; revert to displaying as `^L'. However, the glyphs for the
;; spaces/tabs/new-lines will not re-appear, since this only removes
;; the `C-l'-entry in the window-display-list, not the entire list.
(pretty-control-l-mode 0)
nil

;; Nil the window-display-table, to verify that is the culprit.  This
;; will re-enable the glyphs defined by whitespace-mode (since they
;; are still in the buffer display-table).
(set-window-display-table nil nil)
nil

;; To round of; this is my Emacs-version:
(emacs-version)
"GNU Emacs 23.4.1 (i686-pc-linux-gnu, GTK+ Version 2.24.12)
 of 2012-09-22 on akateko, modified by Debian"

;;End.
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Sorry for your trouble. I don't see the problem you report, following your recipe. Perhaps the description is not complete? I can turn on both pretty-control-l-mode and whitespace-mode, and the behavior I see for each seems normal. Perhaps there is some custom setting you use for whitespace-style or something?

Anyway, maybe it would help if you make a change like this to pretty-control-l-mode. If so, let me know and I will apply it to pp-c-l.el. (To test, set the new option to nil.)

 (defcustom pp^L-use-window-display-table-flag t
   "Non-nil: use `window-display-table'; nil: use `buffer-display-table`."
   :type 'boolean :group 'Pretty-Control-L)

 (define-minor-mode pretty-control-l-mode
     "Toggle pretty display of Control-l (`^L') characters.
 With ARG, turn pretty display of `^L' on if and only if ARG is positive."
   :init-value nil :global t :group 'Pretty-Control-L
   (if pretty-control-l-mode
       (add-hook 'window-configuration-change-hook 'refresh-pretty-control-l)
     (remove-hook 'window-configuration-change-hook 'refresh-pretty-control-l))
   (walk-windows
    (lambda (window)
      (let ((display-table  (if pp^L-use-window-display-table-flag ; <=========
                                (or (window-display-table window)
                                    (make-display-table))
                              (if buffer-display-table
                                  (copy-sequence buffer-display-table)
                                (make-display-table)))))
        (aset display-table ?\014 (and pretty-control-l-mode
                                       (pp^L-^L-display-table-entry window)))
        (if pp^L-use-window-display-table-flag                     ; <=========
            (set-window-display-table window display-table)
          (setq buffer-display-table display-table))))
    'no-minibuf
    'visible))
share|improve this answer
    
BTW, I wonder if the hierarchy of display tables described in the doc shouldn't perhaps be applied using inheritance of some kind. Seems a bit primitive for one level (e.g. window) to completely shadow a lower level (e.g. buffer). You might consider sending a question about this to M-x report-emacs-bug. –  Drew Sep 24 at 16:36
    
Ping? Could you please let me know if the change above helps? Thx. –  Drew Oct 14 at 18:12
    
I just read this answer (I have not been around this part of the Internet for a while...). I will check this when I get round to it, perhaps in a few days or so. I'll get back with an ‘Answer approved’ (if it works), or comments (otherwise), as appropriate, later. –  Johan E Oct 25 at 22:32
    
I edited the question to add a more fleshed-out recipe for showing the problem. I'd be interested whether you get the same results. --- Also, is there a way to shadow a system installed .el-file with a user-supplied one (I'm really just a “user”, not a lisp-programmer...)? I don't really feel like messing with the files installed by deb-packages. (That's why I did the problem-recipe before testing your answer...) –  Johan E Oct 27 at 1:02
    
Five seconds after I wrote the last comment I realized that I could just paste the code into *scratch* and C-j-run it to test. (No need to edit any files.) The results: It works a charm! Thank you! (=> Answer accepted) However, I'd still like to know if you get the same results as I from my problem-recipe (before patching the code). –  Johan E Oct 27 at 1:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.