kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
874 stars 132 forks source link

No newline at end of file after re-exporting #666

Closed andreyorst closed 2 years ago

andreyorst commented 2 years ago

Actual Behavior

Unlike initial export, after re-exporting a buffer, either from a file or from a subtree, the resulting file has no newline at the end.

Magit complains about it:

image

(In the old times, the absence of a final newline meant that the file is a binary data)

Expected Behavior

Newline is appended.

How to Reproduce the Issue

Re-export any existing file.

Ox-Hugo Debug Information

Debug Info # Debug information for `ox-hugo` ## Emacs Version GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4) of 2022-08-09 (commit 2504d19dade7bcfcce7cd93011edf06f3c955a50) ## Org Version Org mode version 9.5.4 (release_9.5.4-17-g6e991f @ /home/alist/.local/share/emacs/29.0.50/lisp/org/) ## Hugo Version hugo v0.93.3+extended linux/amd64 BuildDate=unknown ### Org `load-path` shadows No Org mode shadows found in `load-path` ## `ox-hugo` defcustoms
org-hugo-section "posts"
org-hugo-use-code-for-kbd nil
org-hugo-preserve-filling t
org-hugo-delete-trailing-ws t
org-hugo-prefer-hyphen-in-tags t
org-hugo-allow-spaces-in-tags t
org-hugo-tag-processing-functions (org-hugo–tag-processing-fn-replace-with-spaces-maybe org-hugo–tag-processing-fn-replace-with-hyphens-maybe)
org-hugo-auto-set-lastmod nil
org-hugo-export-with-toc nil
org-hugo-export-with-section-numbers nil
org-hugo-front-matter-format "toml"
org-hugo-default-static-subdirectory-for-externals "ox-hugo"
org-hugo-external-file-extensions-allowed-for-copying ("jpg" "jpeg" "tiff" "png" "svg" "gif" "mp4" "pdf" "odt" "doc" "ppt" "xls" "docx" "pptx" "xlsx")
org-hugo-date-format "%Y-%m-%dT%T%z"
org-hugo-paired-shortcodes ""
org-hugo-suppress-lastmod-period 0.0
org-hugo-front-matter-format "toml"
kaushalmodi commented 2 years ago

ox-hugo doesn't distinguish between first and later exports.

Were your initial exports on the same day? I am wondering a scenario where you probably had require-final-newline set to t, but then you removed it later before your later exports.

andreyorst commented 2 years ago

oh right, you're correct, there's no newline at the end of the file after the initial export too, I just never noticed this. require-final-newline is set to t by default, and I never touch this variable.

kaushalmodi commented 2 years ago

require-final-newline is set to t by default, and I never touch this variable

ox-hugo doesn't touch this variable either. Is it possible you inherited that variable through some config suite like Spacemacs or Doom?

In any case, if you add (setq require-final-newline t) to your config and evaluate that, you will always have empty newlines at the end of your files after each save. The default of this variable is nil and in that, the file save operation doesn't modify the end of file newlines.


FWIW I like to end files with newlines and I have (setq require-final-newline t) in my Emacs config.

andreyorst commented 2 years ago

ox-hugo doesn't touch this variable either. Is it possible you inherited that variable through some config suite like Spacemacs or Doom?

no, I don't use any distributions. I now see that this variable is modified by some major modes, and my assumption that it's t by default was misled. Thanks for the suggestion, I'll add this variable to my init. Closing.

kaushalmodi commented 2 years ago

this variable is modified by some major modes

That should be reported as a bug. That variable should be changed only by the user.

kaushalmodi commented 2 years ago

That variable should be changed only by the user.

Correcting myself a bit. A major mode should not change that variable to nil.

From https://www.gnu.org/software/emacs/manual/html_node/emacs/Customize-Save.html,

Some major modes are designed for specific kinds of files that are always supposed to end in newlines. Such major modes set the variable require-final-newline to the value of mode-require-final-newline, which defaults to t. By setting the latter variable, you can control how these modes handle final newlines.