Skip to content

Instantly share code, notes, and snippets.

@tkurtbond
Last active February 14, 2024 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkurtbond/bf8c1b3dff4a1c56aeb43271726d276b to your computer and use it in GitHub Desktop.
Save tkurtbond/bf8c1b3dff4a1c56aeb43271726d276b to your computer and use it in GitHub Desktop.
Don't want the first line of a git commit COMMIT_EDITMSG buffer in Emacs to wrap?
(defun tkb-magit-commit-fill-nobreak-p ()
"Don't fill on the first line of a magit commit message."
(= 1 (line-number-at-pos)))
(defun tkb-magit-commit-find-file-hook ()
(interactive)
(when (string-match "COMMIT_EDITMSG\\'" (buffer-file-name))
(make-local-variable 'fill-nobreak-predicate)
(add-to-list 'fill-nobreak-predicate #'tkb-magit-commit-fill-nobreak-p)))
;; Using add-to-list without specifying APPEND didn't work because
;; that added it to the front of the list and the
;; git-commit-setup-check-buffer find file hook ran later. The
;; git-commit-setup-check-buffer runs git-commit-setup which runs
;; normal-mode which runs kill-all-local-variables, which wiped out
;; what tkb-magit-commit-find-file-hook was trying to do.
(add-to-list 'find-file-hook #'tkb-magit-commit-find-file-hook t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment