I'm working with tex files that have usually long lines of text. I enabled in magit the fine coloration of errors by using:

(setq-default magit-diff-refine-hunk 'all)

and now I'd like to disable the truncate-line function. How could I do that?


  • 1
    just add a hook to magit-diff-mode and call toggle-truncate-line. That should do it – Chakravarthy Raghunandan May 15 '18 at 10:58
  • Why would you want to toggle it automatically? Surely you either want it "on" or "off"; rather than "the opposite of whatever it is at the moment" ? – phils May 15 '18 at 11:25
  • And your text is confusing. Do you want this for diff-mode (as per your subject), or magit-diff-mode (which I would expect from the rest of your text) ? – phils May 15 '18 at 11:29
  • @phils Yes indeed, I sayed toggle just because by default it's always off. And I want it for the diff-mode of magit, which appears to be magit-diff-mode, I though that magit was using an already existing mode to display this, and I didn't want to interfer with it. – tobiasBora May 15 '18 at 12:43

My best guess is that this is what you want:

(defun my-truncate-lines ()
  (setq truncate-lines t))

(add-hook 'magit-diff-mode-hook 'my-truncate-lines)
  • indeed I wasn't clear (just updated), by default it truncates the line and I want not to truncate them. So I want "nil" instead of "t", but else it's perfect, I did not known about the magit-diff-mode-hook thing. Thanks. – tobiasBora May 15 '18 at 12:47
  • All modes have a mode hook, which is always the name of the mode function with a -hook suffix. (In the case of minor modes, the hook is called when the mode is enable or disabled, so you often want to test the mode variable so that you can act in accordance with its current state.) – phils May 15 '18 at 12:49
  • This probably goes without saying, but as you actually wanted a value of nil the name my-truncate-lines would be somewhat misleading, so you probably want to rename that to something more appropriate. – phils May 15 '18 at 12:58
  • Yes thanks, that's what I did. But actually, in my mind truncate looks like "I cut the line and put the following below", while in fact it's "hide the last part of the line". Anyway, thanks. – tobiasBora May 15 '18 at 13:00

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.