3

The boolean variable truncate-lines controls whether continuation lines are displayed or not. I use this when I am checking some log file where the very long lines are truncated thanks to a previous (setq truncate-lines t). This is convenient since the relevant contents is usually at the beginning of the lines. However I sometimes need to see the end of the inspected lines and I'll occasionally toggle truncate-lines on and off (this is done in code temporarily bound to a function key).

The problem is that toggling truncate-lines on and off does not update the display unless I do some editing, or move the cursor far enough, or .. I don't know what. I tried to insert a (redisplay t) in my toggling code but this is not enough.

What bit of elisp magic will cause the display to be updated according to the new value of truncate-lines once it is changed? And, by the way, is the lack of immediate update a bona fide bug?

How to reproduce the problem: After some investigation, it seems that the problem appears because I invoke the toggle via some key binding and not by execute-extended-command aka M-x. Here is a test file for you to download. Start with emacs -Q test_file, then eval-defun the first expression. Now M-x ttl does the toggle ok but on my machine hitting CTRL l (now bound to ttl) does the toggle without redisplay. If I move to end of buffer, the redisplay is activated. FWIW I use emacs 24.5.1

Added Jan. 5th: it turns out that the behaviour described above is due to a minor bug that will be fixed in Emacs 25, see here. In principle there is nothing wrong with changing truncate-lines directly without going through toggle-truncate-lines.

phs
  • 1,095
  • 6
  • 13
  • 5
    Can you provide a recipe starting from `emacs -Q` to reproduce the problem? I `toggle-truncate-lines` a lot, and I don't recall it ever failing to have an immediate effect on the visual state of the buffer. – phils Jan 03 '16 at 12:07
  • I've now just done that. Thanks for the suggestion. It turns out that the redisplay works ok when I toggle via `execute-extended-command` aka `M-x`. It fails when I toggle via key bindings. – phs Jan 03 '16 at 13:12
  • 5
    You should use `toggle-truncate-lines` rather than changing directly the value of `truncate-lines`. `(global-set-key "\C-l" 'toggle-truncate-lines)` does work. [doc](https://www.gnu.org/software/emacs/manual/html_node/emacs/Line-Truncation.html#Line-Truncation) – JeanPierre Jan 03 '16 at 13:51
  • 1
    @JeanPierre: that's probably the answer. Could you change your comment to an answer? – Dan Jan 03 '16 at 19:58
  • @JeanPierre: Yes, please do post it as an answer – Drew Jan 04 '16 at 06:29
  • Thanks JeanPierre. I did not know that a `toggle-truncate-lines` function already existed. This solves my problem. The code in `simple.el` is more involved than just a `setq` :-) It is really too bad that the documentation string for `truncate-lines` does not refer to the toggle function and recommend using it. – phs Jan 04 '16 at 06:45
  • 1
    phs: You can `M-x report-emacs-bug` to suggest a documentation change. – phils Jan 04 '16 at 08:47
  • @phils: good idea. I just did that. – phs Jan 04 '16 at 09:42

1 Answers1

3

You should use the command toggle-truncate-lines rather than changing directly the value of variabletruncate-lines. This command does ensure the display is updated (apparently through force-mode-line-update although nor its name neither its docstring does suggest that).

It is described in emacs manual but unfortunately not mentionned in truncate-lines docstring nor in the section about truncation of elisp manual.

JeanPierre
  • 7,323
  • 1
  • 18
  • 37