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.

  • 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 3 '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 3 '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 – JeanPierre Jan 3 '16 at 13:51
  • 1
    @JeanPierre: that's probably the answer. Could you change your comment to an answer? – Dan Jan 3 '16 at 19:58
  • 1
    phs: You can M-x report-emacs-bug to suggest a documentation change. – phils Jan 4 '16 at 8:47
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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