2

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?

Thanks!

4
  • 2
    just add a hook to magit-diff-mode and call toggle-truncate-line. That should do it May 15, 2018 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, 2018 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, 2018 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, 2018 at 12:43

2 Answers 2

2

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)
4
  • 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, 2018 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, 2018 at 12:49
  • 1
    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, 2018 at 12:58
  • 1
    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, 2018 at 13:00
0

This would be a little tip: if you just use magit-mode-hook instead of magit-diff-mode-hook in the solution already answered can also preserve diff lines under "Staged changes" and "Unstaged changes" on the magit-status (magit home) as well as magit-diff buffer.

;; just summarized the above teachers' comments.
(defun untruncate-lines ()
  (setq truncate-lines nil)) 

(add-hook 'magit-mode-hook 'untruncate-lines) ;; also works for `magit-diff-mode`

Your Answer

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

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