1

One of the nice features of Emacs is that you can use Tab for in-line completions and Tab-Tab for showing possible completions to already typed text in a separate buffer if there are multiple of them. The proposed completions 'know' about the context in which the text was typed and show only related and making sense completions.

Happy to find this out on my way to mastering Emacs I had assumed that now I have a tool at hand which would help me to change any desired option and setting by just searching for completions with a given meaningful keyword.

In case of removing the marking of a line break from the end of a line I have assumed that using the keyword 'line' or/and 'visual' should show me completions giving enough hints about what a method or option do in order to choose and change it.

Somehow the keywords line ( or -line- ) and visual ( or -visual, etc.) do not provide the expected completion indicating by its wording switched on visualization of a line break.

This leads to the question stated in the question title:

How to switch off showing a line break marking dollar sign $ at the end of a line?

Do the Emacs version 27 and 28 differ if it comes to setting this visualization on/off? I am currently using Emacs 28, but started with 27 and have both versions installed on my system (27 as /usr/bin/emacs and 28 as usr/local/bin/emacs).

Below an image showing what I am speaking about with red arrows pointing to the shown dollar sign at the line end which visualization I am seeking to switch off.

$

( for those ones interested in exploring the subject mentioned in the image here the link: http://computer-programming-forum.com/56-python/677f8f30f7636c7e.htm )

3 Answers 3

3

Thanks for Fran Burstall's answer, but it has some disadvantages. So I post this answer as another choice.

Since OP has toggled whitespace-mode on, so simply disabling whitespace-newline-mode will make SPC and TAB indicators disappear:

enter image description here

To avoid what I described above, add the following code to your .emacs:

(defun Claudio-whitespace-display-newline (&optional toggle-when-nil)
  "This function controls whether `whitespace-mode' visualizes newlines.

Call it only when `whitespace-mode' is on locally.

`M-x Claudio-whitespace-display-newline' or `(Claudio-whitespace-display-newline)' or `(Claudio-whitespace-display-newline nil)':
toggle newline visualization;

`(Claudio-whitespace-display-newline POSITIVE-NUMBER)':
enable newline visualization;

Call with other arguments:
disable newline visualization.

Written by Shynur, for Claudio"
  (interactive)
  (require 'whitespace)
  (unless whitespace-mode
    (error "Claudio-whitespace-display-newline: this function makes sense only when whitespace-mode is on locally"))
  (cond
   ;; As this function's argument's name said, this form will toggle the display of 'newline'.
   ((null toggle-when-nil)
    (Claudio-whitespace-display-newline
     ;; If 'newline' is displayed, turn it off; otherwise, turn on.
     ;; `whitespace-active-style' is described in 'whitespace.el';
     ;; the presence of `newline-mark' means that: 'newline' is displayed.
     (if (memq 'newline-mark whitespace-active-style)
         -1
       1)))
   ;; Instead of toggling, you want to directly turn it on/off.
   (t
    (let ((new-style (remove 'newline-mark whitespace-style))) ; Make a new 'whitespace-style' without `newline-mark'.
      ;; !!! `whitespace-mode' will read `whitespace-style' _when_it_starts_,
      ;; !!! so you should turn it off now (and then turn it on).
      (whitespace-mode -1)
      (let ((whitespace-style (if (> toggle-when-nil 0)
                                  ;; If you want to display 'newline',
                                  ;; add a 'newline-mark' to `new-style' which is created just now;
                                  (push 'newline-mark new-style)
                                ;; otherwise, don't modify it.
                                new-style)))
        ;; Now `new-style' has been assigned to `whitespace-style',
        ;; which will tell `whitespace-mode' what to display.
        (whitespace-mode)))))) ; Enable it.
6
  • 2
    @Claudio: See whitespace.el and you will find it provides both these two modes. So, yes, you're right, they reuse code to some extent. Since you've turned whitespace-mode on and whitespace-newline-mode off, the simplest way is just to leave whitespace-newline-mode off and re-turn whitespace-mode. But wait, before turning on whitespace-mode, don't forget to tell it what kind of whitespace should be displayed. BTW, you cannot figure out how Elisp works just by asking questions and watching some answers, you need to deep into it. I recommend you the book Emacs Lisp Intro.
    – shynur
    Commented Mar 19, 2023 at 18:04
  • @Claudio: To evaluate an elisp form in a buffer, put the cursor after the right parenthese of the form and use C-x C-e. (If you want to disable the newline indicators globally, putting them in your .emacs is just OK because it’s simple. And, dont forget to replace whitespace-mode with global-whitespace-mode.)
    – shynur
    Commented Mar 19, 2023 at 18:39
  • @Claudio: whitespace-mode and global-whitespace-mode are functions and they only receive one argument. That argument has nothing to do with the details how the mode displays whitespace indicators. If you read my code, you will note the whitespace-display-mappings, which controls how the mode display whitespaces. So any other questions?
    – shynur
    Commented Mar 19, 2023 at 19:09
  • @Claudio: OK, I will remove the word “addendum” in my answer... It seems that my wording confused you.
    – shynur
    Commented Mar 19, 2023 at 19:15
  • Let us continue this discussion in chat.
    – oOosys
    Commented Mar 19, 2023 at 19:17
1

Do M-x whitespace-newline-mode to toggle the visualisation of newlines.

4
  • Thanks for your helpful reply pointing to the names of the options I was looking for. The right keywords to look for them were newline and whitespace. The problem with your answer is that toggling the visualization of newlines does not always work, depending on the history of invoking combinations of whitespace-mode and whitespace-newline-mode. Once switched off it can happen that toggling whitespace-newline-mode does not bring the $ at the line end back. Beside this switching the $ off has as a side-effect switching off the visualization of spaces. Weird behavior hard to intuitively predict.
    – oOosys
    Commented Mar 19, 2023 at 17:44
  • If this does not work as documented then you should report a bug. Commented Mar 19, 2023 at 17:51
  • The documentation tells only that it toggles a 'minor mode' on/off, not that it switches the visualization on/off. What will be actually displayed in a buffer is not covered in the documentation. "Toggle newline visualization" is just only a name/title of a minor mode switch related to newline visualization and not part of the explanation. It does not necessarily guarantee that it will actually result in what its title name suggests, right?
    – oOosys
    Commented Mar 19, 2023 at 18:17
  • See the trailing comment in my answer for a reason why whitespace-newline-mode should not be used to switch off the visualization of newline in case described in my question (i.e. with whitespace-mode turned on).
    – oOosys
    Commented Mar 19, 2023 at 19:05
0

Below all the possible outcomes you can achieve by using combinations of M-x whitespace-mode and M-x whitespace-newline-mode:

enter image description here

enter image description here

enter image description here

enter image description here

The pure switching the newline $ marker off while preserving visualization of spaces can't be achieved by switching these two modes on/off and would require other measures like for example these these mentioned in the other answer by Shynur.

Worth to know in this context is that whitespace.el provides following information:

Use whitespace-newline-mode only for NEWLINE visualization exclusively. For other visualizations, including NEWLINE visualization together with (HARD) SPACEs and/or TABs, please, use whitespace-mode.

In other words whitespace-newline-mode toggling is designed to result in toggling newline visualization only if the whitespace-mode is turned off.

Using it with whitespace-mode turned ON is nor checked nor prevented, but is a kind of misusing it for a purpose it was not designed for (therefore its side-effects and lack of function are probably not a valid reason for filing a bug report).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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