summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2023-03-28 21:55:08 +0200
committerUlrich Müller <ulm@gentoo.org>2023-03-28 21:55:08 +0200
commitbd08feb5e7a3b0f7c79534a13be0a3ade3c210d0 (patch)
tree4c284bb78feca6ccc6287c508da321129d5bc48c
parentVersion 1.63 released (diff)
downloadebuild-mode-bd08feb5e7a3b0f7c79534a13be0a3ade3c210d0.tar.gz
ebuild-mode-bd08feb5e7a3b0f7c79534a13be0a3ade3c210d0.tar.bz2
ebuild-mode-bd08feb5e7a3b0f7c79534a13be0a3ade3c210d0.zip
Squash empty lines when saving the buffer
* ebuild-mode.el (ebuild-mode-squash-empty-lines): New function. (ebuild-repo-mode-before-save): Call it. Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r--ChangeLog5
-rw-r--r--ebuild-mode.el14
2 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5736200..bc62590 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-03-28 Ulrich Müller <ulm@gentoo.org>
+
+ * ebuild-mode.el (ebuild-mode-squash-empty-lines): New function.
+ (ebuild-repo-mode-before-save): Call it.
+
2023-03-26 Ulrich Müller <ulm@gentoo.org>
* Version 1.63 released.
diff --git a/ebuild-mode.el b/ebuild-mode.el
index d6a49aa..4e85e4b 100644
--- a/ebuild-mode.el
+++ b/ebuild-mode.el
@@ -365,6 +365,13 @@ Compatibility function for XEmacs."
(delete-region (match-beginning 0) (point))
(indent-to end-col)))))))
+(defun ebuild-mode-squash-empty-lines ()
+ "Replace multiple consecutive empty lines by a single one."
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "^\n+$" nil t)
+ (replace-match ""))))
+
(defun ebuild-mode-update-copyright ()
"Update the copyright notice in the ebuild's header."
(save-excursion
@@ -793,9 +800,10 @@ This will be added to the `write-contents-functions' hook."
(when ebuild-mode-fix-whitespace
;; trim trailing whitespace, except for patches
(delete-trailing-whitespace)
- ;; tabify whitespace for ebuilds
- (if (derived-mode-p 'ebuild-mode)
- (ebuild-mode-tabify)))
+ ;; tabify whitespace and squash multiple empty lines for ebuilds
+ (when (derived-mode-p 'ebuild-mode)
+ (ebuild-mode-tabify)
+ (ebuild-mode-squash-empty-lines)))
(when ebuild-mode-update-copyright
(ebuild-mode-update-copyright)
;; call it only once per buffer