From 16e3c570dbd6c1bf7161ca57715a043d241b65a0 Mon Sep 17 00:00:00 2001 From: luxick Date: Tue, 7 Oct 2025 15:05:50 +0200 Subject: [PATCH] Add helper functions for file encoding trouble This will hide the extra line ending markers on windows. --- init.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/init.el b/init.el index 70235cc..aaaec48 100644 --- a/init.el +++ b/init.el @@ -3,6 +3,8 @@ (set-default-coding-systems 'utf-8) (set-language-environment 'utf-8) (set-selection-coding-system 'utf-8) +;; Always use Unix line endings +(setq-default buffer-file-coding-system 'utf-8-unix) ;; personal.el - personal settings (setq personal-file "~/.emacs.d/personal.el") @@ -388,6 +390,24 @@ (slime-setup '(slime-fancy slime-quicklisp slime-asdf)) (add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1))) +;; Automatically hide line ending markers when unix/ms differences occur. +;; This would usually be the case for files that have been edited on android and opened on windows. +(defun hide-eol () + "Hide the ^M markers in the current buffer" + (interactive) + (setq buffer-display-table (make-display-table)) + (aset buffer-display-table ?\^M [])) + +(defun hide-eol-if-crlf () + "Hide ^M characters if file has CRLF line endings" + (save-excursion + (goto-char (point-min)) + (when (re-search-forward "\r$" nil t) + (hide-eol)))) + +;; Add to find-file-hook to run on every file open +(add-hook 'find-file-hook 'hide-eol-if-crlf) + ;; Misc functions (autoload 'diff-no-select "diff")