Skip to content

Commit

Permalink
Merge branch 'master' into new-coding-system-advice
Browse files Browse the repository at this point in the history
  • Loading branch information
10sr authored Oct 26, 2024
2 parents 030f4b3 + c707d8d commit 19ded31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ jobs:
- os: macos-latest
emacs-version: snapshot
experimental: true
exclude:
# 2023/8/2 Recently this test always fails
# so remove this until it works
- os: windows-latest
emacs-version: snapshot
experimental: true
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ Current Emacs plugin coverage for EditorConfig's [properties][]:
* `end_of_line`
* `charset`
* `trim_trailing_whitespace`
* `insert_final_newline = true` is supported
* ~~`insert_final_newline = false`~~ is not enforced
(as in trailing newlines actually being removed automagically),
we just buffer-locally override any preferences that would auto-add them
to files `.editorconfig` marks as trailing-newline-free
* `insert_final_newline`
* `max_line_length`
* ~~`file_type_ext` (Experimental)~~ (See below)
* ~~`file_type_emacs` (Experimental)~~ (See below)
Expand Down
22 changes: 18 additions & 4 deletions editorconfig.el
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,17 @@ This function will revert buffer when the coding-system has been changed."
(revert-buffer-with-coding-system coding-system)))
(setq editorconfig--apply-coding-system-currently nil)))))

(defun editorconfig--delete-final-newline ()
"Ensure the buffer does not end with a newline.
Does nothing if the buffer is read-only."
(unless buffer-read-only
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(while (looking-at-p "^$")
(delete-char -1))))))

(defun editorconfig-set-trailing-nl (final-newline)
"Set up requiring final newline by FINAL-NEWLINE.
Expand All @@ -595,12 +606,15 @@ to non-nil when FINAL-NEWLINE is true."
("true"
;; keep prefs around how/when the nl is added, if set - otherwise add on save
(setq-local require-final-newline (or require-final-newline t))
(setq-local mode-require-final-newline (or mode-require-final-newline t)))
(setq-local mode-require-final-newline (or mode-require-final-newline t))
(remove-hook 'before-save-hook
#'editorconfig--delete-final-newline t))

("false"
;; FIXME: Add functionality for actually REMOVING any trailing newlines here!
;; (rather than just making sure we don't automagically ADD a new one)
(setq-local require-final-newline nil)
(setq-local mode-require-final-newline nil))))
(setq-local mode-require-final-newline nil)
(add-hook 'before-save-hook
#'editorconfig--delete-final-newline nil t))))

(defun editorconfig--delete-trailing-whitespace ()
"Call `delete-trailing-whitespace' unless the buffer is read-only."
Expand Down

0 comments on commit 19ded31

Please sign in to comment.