-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the auto-export snippet for per-file flow with Windows style paths #185
Comments
@StevenTammen Can you post the output of this: #182 (comment). Knowing that output will help me better fix that snippet for Windows uses. |
Sure. Here's the full output from an example file after I save:
The relevant bit then is
|
That explains why it didn't work for you earlier.. Emacs represents paths internally with I'll post a cleaner solution for this tomorrow. |
@StevenTammen Can you try the below and see if it still works. Ensure that you restart emacs so that the earlier workaround is not effective. Note the doc string I have in there:
(defconst my/hugo-org-content-dirs '("C:/Users/steve/Desktop/Projects/steventammen.com/org/")
"List of directories containing Org files meant for per-file flow.
On Windows too, the directory paths must be specified with forward-slashes:
Wrong: C:\\foo\\bar\\content-org\\
Right: C:/foo/bar/content-org/")
(defun my/org-hugo-publish-current-buffer-as-post ()
"Export current file if it's a valid post for per-file `ox-hugo' flow.
Current file is exported using `org-hugo-export-to-md' if:
- it is present in one of the directories in
`my/hugo-org-content-dirs', and
- contains the \"#+title\" keyword.
This function is meant to be added to `after-save-hook' only for
Org files."
(cl-letf ((fname (file-truename (buffer-file-name)))
((symbol-function 'file-in-org-content-dir-p)
(lambda (dir)
(string-prefix-p (file-truename dir) fname :ignore-case))))
(when (and fname
(cl-remove-if-not #'file-in-org-content-dir-p
my/hugo-org-content-dirs)
(save-excursion ;Check that the file has #+title keyword
(goto-char (point-min))
(>= (let ((case-fold-search t))
(how-many "^#\\+title:"))
1)))
(org-hugo-export-to-md))))
(defun my/org-mode-hook-fn ()
"My Org mode customization."
(add-hook 'after-save-hook #'my/org-hugo-publish-current-buffer-as-post :append :local))
(add-hook 'org-mode-hook #'my/org-mode-hook-fn) |
The code above is not working for me. I had already tried changing the slashes when I was first having problems: double backslashes, forward slashes, etc. Nothing seemed to work Here's the full code I tested in my .spacemacs user configuration section:
|
Thanks for trying. Try this one another iteration: ;; ox-hugo config, auto-export on save
(use-package ox-hugo
:ensure t
:after ox
:init
(defconst my/hugo-org-content-dirs '("C:/Users/steve/Desktop/Projects/steventammen.com/org/")
"List of directories containing Org files meant for per-file flow.
On Windows too, the directory paths must be specified with forward-slashes:
Wrong: C:\\foo\\bar\\content-org\\
Right: C:/foo/bar/content-org/")
(defun my/org-hugo-publish-current-buffer-as-post ()
"Export current file if it's a valid post for per-file `ox-hugo' flow.
Current file is exported using `org-hugo-export-to-md' if:
- it is present in one of the directories in
`my/hugo-org-content-dirs', and
- contains the \"#+title\" keyword.
This function is meant to be added to `after-save-hook' only for
Org files."
(cl-letf ((fname (buffer-file-name))
((symbol-function 'file-in-org-content-dir-p)
(lambda (dir)
(message "dbg: dir: %S" dir)
(message "dbg: dir truename: %S" (file-truename dir))
(message "dbg: fname: %S" fname)
(message "dbg: is-prefix?: %S"
(string-prefix-p (expand-file-name dir) fname :ignore-case))
(string-prefix-p (expand-file-name dir) fname :ignore-case))))
(message "dbg: valid dirs: %S" (cl-remove-if-not #'file-in-org-content-dir-p
my/hugo-org-content-dirs))
(message "dbg: num titles: %d" (save-excursion ;Check that the file has #+title keyword
(goto-char (point-min))
(let ((case-fold-search t))
(how-many "^#\\+title:"))))
(when (and fname
(cl-remove-if-not #'file-in-org-content-dir-p
my/hugo-org-content-dirs)
(save-excursion ;Check that the file has #+title keyword
(goto-char (point-min))
(>= (let ((case-fold-search t))
(how-many "^#\\+title:"))
1)))
(org-hugo-export-to-md))))
(defun my/org-mode-hook-fn ()
"My Org mode customization."
(add-hook 'after-save-hook #'my/org-hugo-publish-current-buffer-as-post :append :local))
(add-hook 'org-mode-hook #'my/org-mode-hook-fn)) This should work.. Also please paste the messages that get printed by this. If this works, I will update the ox-hugo manual with the final version without debug messages. |
For some reason nothing is working now. The solution that was working last night is no longer working. It was working before I deleted that code from my config to try your later solution, but when I put it back in (in exactly the same place), it no longer works. I have no idea what's going on. It may well be something entirely apart from your code (i.e., it may be related to my specific configuration). I'll try restarting things to see if I can't get at least something to work. Any ideas? |
That usually helps. As I don't have emacs on Windows, I need your help to fix the above snippet. If you can let me know the messages printed by my last snippet, this can be fixed. I the meanwhile, I am working on a better way to have auto-exporting to work even for per-file flow. You wouldn't need any such snippet any more. |
Well, I'm giving up since I'm getting frustrated. I really should have backed up my config file before I changed it, but I didn't, and now I can't get anything to work. I can still export manually, but perhaps I'll wait for that better solution before I spend more time dealing with the old snippets and their mysteriously inconsistent behavior. I would be less annoyed if it had never worked to begin with... |
Works for either flow: per-subtree or per-file Fixes #185.
Git commit more often! :) Well... once your frustration has worn off try out this branch: https://github.com/kaushalmodi/ox-hugo/tree/auto-export-on-save
|
I'd be happy to test, but I'm not entirely sure how to accomplish step 1 vis-a-vis Spacemacs. If you perhaps explained it in more detail I could try it. Or I could just wait. Well, I used the following
And copied the code above into I might have done something wrong. It also looks like your code snippet above contains too many parentheses on the end (one extra). But maybe I'm wrong on that too. |
Works for either flow: per-subtree or per-file Fixes #185.
Works for either flow: per-subtree or per-file Fixes #185.
This got auto-closed as I just merged the branch that was linked with this issue. Follow the instructions on https://ox-hugo.scripter.co/doc/auto-export-on-saving/. Let me know if it finally works for you or not, or if the documentation needs any clarification. |
It works perfectly for me, and this is much simpler for those of us who are just getting into elisp/Emacs packages. You also got this implemented really fast! 👍 Some documentation suggestions: Clarifying exactly what code goes in the config file On the auto-export page you say the following:
But on the usage page, two of the methods presented (use-package and Spacemacs -- which is what I used) do not use You could perhaps make this more clear by rephrasing to something like
Org directory It took me a couple minutes to figure out exactly what
Since for me the path was just Perhaps something like the below would be easier for us newer people?
Multiple projects Maybe this is just self-evident, but it was not documented as far as I could tell: is setting up ox-hugo with multiple projects as simple as adding a If you can just add an extra file, you might make the section above read something like
|
Yay! 🎉 Glad it finally worked out. Thanks for the nudge to clean this up.
Not necessarily.. you can use the
OK, I have hopefully improved that section now.
Nope, that's it. Multiple projects support was one of the reasons to do this whole revamp. Please check out the updated documentation -- I have incorporated your feedback in there. Thanks! PS: I appreciate your well-formatted replies. |
#182 (comment)
May be replace the need of that snippet or the Local Variables eval with an Org bind variable or .dir-locals.el set variable, or something like that..
The text was updated successfully, but these errors were encountered: