all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* changing the display of formfeed characters
@ 2018-08-31 11:22 Javier
  2018-09-01 13:51 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Javier @ 2018-08-31 11:22 UTC (permalink / raw)
  To: help-gnu-emacs

There are several suggested ways to display form feed (^L)

http://www.emacswiki.org/emacs/PageBreaks
http://www.emacswiki.org/emacs/PrettyControlL
https://www.emacswiki.org/emacs/pp-c-l.el
http://ergoemacs.org/emacs/modernization_formfeed.html

However all them break whitespace-mode.  Is there a way to display
formfeed ^L without interfering with whitespace-mode?

The issue has been known for long time.

http://lists.gnu.org/archive/html/help-gnu-emacs/2011-03/msg00891.html
https://www.emacswiki.org/emacs/pp-c-l.el

Has somebody come with any idea how to display ^L in some way without
breaking whitespace-mode?

Would it do the trick modifying the display table for ^L with a fixed width string?
Like "=========" and avoiding to dynamically adjust for window width.


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

* Re: changing the display of formfeed characters
  2018-08-31 11:22 changing the display of formfeed characters Javier
@ 2018-09-01 13:51 ` Eli Zaretskii
  2018-09-02 22:40   ` Drew Adams
       [not found] ` <mailman.262.1535809931.1284.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-09-01 13:51 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Javier <invalid@invalid.invalid>
> Date: Fri, 31 Aug 2018 11:22:59 +0000 (UTC)
> 
> There are several suggested ways to display form feed (^L)
> 
> http://www.emacswiki.org/emacs/PageBreaks
> http://www.emacswiki.org/emacs/PrettyControlL
> https://www.emacswiki.org/emacs/pp-c-l.el
> http://ergoemacs.org/emacs/modernization_formfeed.html
> 
> However all them break whitespace-mode.  Is there a way to display
> formfeed ^L without interfering with whitespace-mode?
> 
> The issue has been known for long time.
> 
> http://lists.gnu.org/archive/html/help-gnu-emacs/2011-03/msg00891.html
> https://www.emacswiki.org/emacs/pp-c-l.el
> 
> Has somebody come with any idea how to display ^L in some way without
> breaking whitespace-mode?

AFAICT, those modes break whitespace-mode because they define their
own display table without copying the display table that was in effect
before the mode was switched on.  whitespace-mode does take care of
copying the previous display table, and doesn't override the way the
formfeed is displayed AFAICS.  So maybe activating those other modes
_before_ whitespace-mode will do the trick?  (Caveat: I didn't try
that.)

> Would it do the trick modifying the display table for ^L with a fixed width string?
> Like "=========" and avoiding to dynamically adjust for window width.

Not sure how this question is related, please elaborate.



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

* Re: changing the display of formfeed characters
       [not found] ` <mailman.262.1535809931.1284.help-gnu-emacs@gnu.org>
@ 2018-09-02 20:47   ` Javier
  2018-09-03 16:14     ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Javier @ 2018-09-02 20:47 UTC (permalink / raw)
  To: help-gnu-emacs

>> Has somebody come with any idea how to display ^L in some way without
>> breaking whitespace-mode?
> 
> AFAICT, those modes break whitespace-mode because they define their
> own display table without copying the display table that was in effect
> before the mode was switched on.  whitespace-mode does take care of
> copying the previous display table, and doesn't override the way the
> formfeed is displayed AFAICS.  So maybe activating those other modes
> _before_ whitespace-mode will do the trick?  (Caveat: I didn't try
> that.)

I have just tried activating the display of form-feed before
whitespace-mode, but didn't suceed.

In any case, that solution wouldn't last for long, since the display
table would be changed again whenever the window changes size.  Those
modes adjust the length of the string representing ^L to fit the width
of the window by using 'window-configuration-change-hook.

>> Would it do the trick modifying the display table for ^L with a fixed width string?
>> Like "=========" and avoiding to dynamically adjust for window width.
> 
> Not sure how this question is related, please elaborate.

That would make things easier as the display table would only be modified once,
without changing it on the fly each time the window changes size.


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

* RE: changing the display of formfeed characters
  2018-09-01 13:51 ` Eli Zaretskii
@ 2018-09-02 22:40   ` Drew Adams
  2018-09-03 16:12     ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Drew Adams @ 2018-09-02 22:40 UTC (permalink / raw)
  To: Eli Zaretskii, help-gnu-emacs

> AFAICT, those modes break whitespace-mode because they define their
> own display table without copying the display table that was in effect
> before the mode was switched on.  

FWIW, `pp-c-l.el' creates a display table only when
`(window-display-table WINDOW)' is nil. Otherwise, it just sets the
entry for ^L in that existing display table:

(walk-windows
     (lambda (window)
       (let ((display-table  (or (window-display-table window)
                                 (make-display-table))))
         (aset display-table ?\014 (and pretty-control-l-mode
                                        (pp^L-^L-display-table-entry window)))
         (set-window-display-table window display-table)))
     'no-minibuf
     'visible)



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

* Re: changing the display of formfeed characters
  2018-08-31 11:22 changing the display of formfeed characters Javier
  2018-09-01 13:51 ` Eli Zaretskii
       [not found] ` <mailman.262.1535809931.1284.help-gnu-emacs@gnu.org>
@ 2018-09-03  0:30 ` Nick Helm
       [not found] ` <mailman.318.1535934620.1284.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 13+ messages in thread
From: Nick Helm @ 2018-09-03  0:30 UTC (permalink / raw)
  To: help-gnu-emacs

Javier <invalid@invalid.invalid> writes:

> Has somebody come with any idea how to display ^L in some way without
> breaking whitespace-mode?

You could use whitespace-mode itself to display form-feeds. Assuming you
have whitespace-mode's newline style enabled, try evaling something like
this before you start whitespace-mode:

(add-to-list 'whitespace-display-mappings
             '(newline-mark ?\^L [?= ?= ?=]))

If you want the line to extend across the width of your current window,
you could eval something like this instead:

(add-to-list 'whitespace-display-mappings
             `(newline-mark ?\^L ,(make-vector (1- (window-width)) ?=)))

You might also be able to use window-configuration-change-hook or
similar to adapt the length of the line as you resize the width of your
window.



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

* Re: changing the display of formfeed characters
       [not found] ` <mailman.318.1535934620.1284.help-gnu-emacs@gnu.org>
@ 2018-09-03 13:57   ` Javier
  2018-09-03 17:23     ` Javier
  0 siblings, 1 reply; 13+ messages in thread
From: Javier @ 2018-09-03 13:57 UTC (permalink / raw)
  To: help-gnu-emacs

> You could use whitespace-mode itself to display form-feeds. Assuming you
> have whitespace-mode's newline style enabled, try evaling something like
> this before you start whitespace-mode:
> 
> (add-to-list 'whitespace-display-mappings
>              '(newline-mark ?\^L [?= ?= ?=]))

Thanks for the clue.  This works.

But one needs to be aware that whitespace-display-mappings remains
undefined until you invoke whitespace-mode.

(setq whitespace-display-mappings 
      ;;fancy chars from http://ergoemacs.org/emacs/modernization_formfeed.html
      ;; all numbers are unicode     codepoint in decimal. e.g. (insert-char 182 1)
      '((space-mark 32 [183]  [46]) ; SPACE 32 「 」, 183 MIDDLE DOT 「·」, 46 FULL STOP 「.」
        (space-mark 160 [164] [95])
        (newline-mark 10 [182 10]) ; LINE FEED,
        (tab-mark 9 [9655 9] [92 9])) ; tab
        (newline-mark ?\^L  [?= ?= ?= ?= ?= ?= ?=])  ; FORM FEED
)

whitespace-mode now displays everything including ^L formfeed.

whitespace-newline-mode displays only newlines and formfeed.

> If you want the line to extend across the width of your current window,
> you could eval something like this instead:
> 
> (add-to-list 'whitespace-display-mappings
>              `(newline-mark ?\^L ,(make-vector (1- (window-width)) ?=)))
>
> You might also be able to use window-configuration-change-hook or
> similar to adapt the length of the line as you resize the width of your
> window.
> 

This looks like adding more and more entries to the list
whitespace-display-mappings, but only the older one will be taken into
account.


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

* Re: changing the display of formfeed characters
  2018-09-02 22:40   ` Drew Adams
@ 2018-09-03 16:12     ` Eli Zaretskii
  0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2018-09-03 16:12 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sun, 2 Sep 2018 22:40:41 +0000 (UTC)
> From: Drew Adams <drew.adams@oracle.com>
> 
> > AFAICT, those modes break whitespace-mode because they define their
> > own display table without copying the display table that was in effect
> > before the mode was switched on.  
> 
> FWIW, `pp-c-l.el' creates a display table only when
> `(window-display-table WINDOW)' is nil. Otherwise, it just sets the
> entry for ^L in that existing display table:
> 
> (walk-windows
>      (lambda (window)
>        (let ((display-table  (or (window-display-table window)
>                                  (make-display-table))))
>          (aset display-table ?\014 (and pretty-control-l-mode
>                                         (pp^L-^L-display-table-entry window)))
>          (set-window-display-table window display-table)))
>      'no-minibuf
>      'visible)

This creates a _window_ display-table, when the current window doesn't
have one.  By contrast, whitespace.el creates a _buffer_
display-table.  And window-specific display-table takes precedence
over the buffer-specific one.  Thus, the effect of the above is to
effectively disable the settings made by whitespace-mode.

So if pp-c-l.el wants to be nice to whitespace.el and other similar
modes, it should check not only window-display-table, but also
buffer-display-table, and I think even standard-display-table if the
other two don't exist.  If any one of these exists, pp-c-l.el should
copy it to the window-display-table, and then add its settings there.
Then I think pp-c-l.el will not break whitespace-mode.



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

* Re: changing the display of formfeed characters
  2018-09-02 20:47   ` Javier
@ 2018-09-03 16:14     ` Eli Zaretskii
  0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2018-09-03 16:14 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Javier <invalid@invalid.invalid>
> Date: Sun, 2 Sep 2018 20:47:06 +0000 (UTC)
> 
> >> Has somebody come with any idea how to display ^L in some way without
> >> breaking whitespace-mode?
> > 
> > AFAICT, those modes break whitespace-mode because they define their
> > own display table without copying the display table that was in effect
> > before the mode was switched on.  whitespace-mode does take care of
> > copying the previous display table, and doesn't override the way the
> > formfeed is displayed AFAICS.  So maybe activating those other modes
> > _before_ whitespace-mode will do the trick?  (Caveat: I didn't try
> > that.)
> 
> I have just tried activating the display of form-feed before
> whitespace-mode, but didn't suceed.

Well, it was a stab in the dark anyway.

I think you should complain to the authors of the relevant packages,
because they should generally honor existing display tables where
those don't contradict what the package wants to do.  There's nothing
wrong in whitespace-mode AFAICT, it doesn't even change how ^L is
displayed by default.



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

* Re: changing the display of formfeed characters
  2018-09-03 13:57   ` Javier
@ 2018-09-03 17:23     ` Javier
  2018-09-04  6:43       ` Javier
  0 siblings, 1 reply; 13+ messages in thread
From: Javier @ 2018-09-03 17:23 UTC (permalink / raw)
  To: help-gnu-emacs

I have solved it now.  It only lacks hooks to adjust to the window
width in real time.

Taking the code of whitespace-newline-mode from whitespace.el,
s/newline/formfeed/, adding whitespace-display-mappings in the
let varlist et voilá! a minor mode that displays formfeed and
coexists well with whitespace-mode.

Thanks to Nick Helm for guiding me in the right direction.


(setq formfeed-display-string-length 70)
(setq formfeed-display-string (make-vector formfeed-display-string-length ?-))

(setq whitespace-display-mappings
      ;;fancy chars from http://ergoemacs.org/emacs/modernization_formfeed.html
      ;; all numbers are unicode     codepoint in decimal. e.g. (insert-char 182 1)
      `((space-mark 32 [183]  [46]) ; SPACE 32 「 」, 183 MIDDLE DOT 「·」, 46 FULL STOP 「.」
        (space-mark 160 [164] [95])
        (newline-mark 10 [182 10]) ; LINE FEED,
        (tab-mark 9 [9655 9] [92 9]) ; TAB
        (newline-mark ?\^L  ,formfeed-display-string))  ; FORM FEED
                                                  )

(define-minor-mode global-whitespace-formfeed-mode
  "Toggle global formfeed visualization (Global Whitespace Formfeed mode).
With a prefix argument ARG, enable Global Whitespace Formfeed mode
if ARG is positive, and disable it otherwise.

If called from Lisp, also enables the mode if ARG is omitted or nil,
and toggles it if ARG is `toggle'.

Use `global-whitespace-formfeed-mode' only for FORMFEED
visualization exclusively.  For other visualizations, including
FORMFEED visualization together with (HARD) SPACEs and/or TABs,
please use `global-whitespace-mode'."
  :lighter    " NL"
  :init-value nil
  :global     t
  :group      'whitespace

  (let ((whitespace-style '(face newline-mark newline))
        (whitespace-display-mappings  `( (newline-mark ?\^L ,formfeed-display-string)  )))
    (global-whitespace-mode (if global-whitespace-formfeed-mode
                                1 -1))
    ;; sync states (running a batch job)
    (setq global-whitespace-formfeed-mode global-whitespace-mode)))

(define-minor-mode whitespace-formfeed-mode
  "Toggle formfeed visualization (Whitespace Formfeed mode).
With a prefix argument ARG, enable Whitespace Formfeed mode if ARG
is positive, and disable it otherwise.

If called from Lisp, also enables the mode if ARG is omitted or nil,
and toggles it if ARG is `toggle'.

Use `whitespace-formfeed-mode' only for FORMFEED visualization
exclusively.  For other visualizations, including FORMFEED
visualization together with (HARD) SPACEs and/or TABs, please,
use `whitespace-mode'."
  :lighter    " nl"
  :init-value nil
  :global     nil
  :group      'whitespace
  (let ((whitespace-style '(face newline-mark newline))
        (whitespace-display-mappings  `( (newline-mark ?\^L ,formfeed-display-string)  )))
    (whitespace-mode (if whitespace-formfeed-mode
                         1 -1)))
  ;; sync states (running a batch job)
  (setq whitespace-formfeed-mode whitespace-mode))


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

* Re: changing the display of formfeed characters
  2018-09-03 17:23     ` Javier
@ 2018-09-04  6:43       ` Javier
  2018-09-04  6:50         ` Javier
  0 siblings, 1 reply; 13+ messages in thread
From: Javier @ 2018-09-04  6:43 UTC (permalink / raw)
  To: help-gnu-emacs

It turns out that the code I have just wrote works fine when called
interactively

M-x global-whitespace-formfeed-mode

but if I write this in ~/.emacs

(global-whitespace-newline-mode 1)

enables the whole of whitespace-mode, with spaces and newlines
highlighted, not just formfeed.


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

* Re: changing the display of formfeed characters
  2018-09-04  6:43       ` Javier
@ 2018-09-04  6:50         ` Javier
  2018-09-07  0:26           ` Nick Helm
  2018-09-07  3:56           ` Nick Helm
  0 siblings, 2 replies; 13+ messages in thread
From: Javier @ 2018-09-04  6:50 UTC (permalink / raw)
  To: help-gnu-emacs

The same thing happens in vanilla emacs with the modes defined in whitespace.el

M-x global-whitespace-newline-mode

works fine interactively (only highlights newlines), but if I write in ~/.emacs

(global-whitespace-newline-mode 1)

It highlights spaces and tabs, not just newlines.


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

* Re: changing the display of formfeed characters
  2018-09-04  6:50         ` Javier
@ 2018-09-07  0:26           ` Nick Helm
  2018-09-07  3:56           ` Nick Helm
  1 sibling, 0 replies; 13+ messages in thread
From: Nick Helm @ 2018-09-07  0:26 UTC (permalink / raw)
  To: help-gnu-emacs

Javier <invalid@invalid.invalid> writes:

> The same thing happens in vanilla emacs with the modes defined in whitespace.el
>
> M-x global-whitespace-newline-mode
>
> works fine interactively (only highlights newlines), but if I write in ~/.emacs
>
> (global-whitespace-newline-mode 1)
>
> It highlights spaces and tabs, not just newlines.

I see this here as well. You should open a bug.



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

* Re: changing the display of formfeed characters
  2018-09-04  6:50         ` Javier
  2018-09-07  0:26           ` Nick Helm
@ 2018-09-07  3:56           ` Nick Helm
  1 sibling, 0 replies; 13+ messages in thread
From: Nick Helm @ 2018-09-07  3:56 UTC (permalink / raw)
  To: help-gnu-emacs

Javier <invalid@invalid.invalid> writes:

> The same thing happens in vanilla emacs with the modes defined in whitespace.el
>
> M-x global-whitespace-newline-mode
>
> works fine interactively (only highlights newlines), but if I write in ~/.emacs
>
> (global-whitespace-newline-mode 1)
>
> It highlights spaces and tabs, not just newlines.

Also see bug#12496
http://lists.gnu.org/archive/html/bug-gnu-emacs/2012-09/msg01302.html




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

end of thread, other threads:[~2018-09-07  3:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-31 11:22 changing the display of formfeed characters Javier
2018-09-01 13:51 ` Eli Zaretskii
2018-09-02 22:40   ` Drew Adams
2018-09-03 16:12     ` Eli Zaretskii
     [not found] ` <mailman.262.1535809931.1284.help-gnu-emacs@gnu.org>
2018-09-02 20:47   ` Javier
2018-09-03 16:14     ` Eli Zaretskii
2018-09-03  0:30 ` Nick Helm
     [not found] ` <mailman.318.1535934620.1284.help-gnu-emacs@gnu.org>
2018-09-03 13:57   ` Javier
2018-09-03 17:23     ` Javier
2018-09-04  6:43       ` Javier
2018-09-04  6:50         ` Javier
2018-09-07  0:26           ` Nick Helm
2018-09-07  3:56           ` Nick Helm

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.