2

I'm trying to autoexport a file from orgmode to html, so I decided to make a function to check the major mode of the buffer and check if the buffer has open the file that I want to export but when I try it the function export all the orgmode files and not the one that I want.

Here is the code:

(defun org-mode-export-hook()
"Auto export html"
(when (eq major-mode 'org-mode)
    (when (eq buffer-file-name "/home/rafa/org/to-read.org")
        (org-twbs-export-to-html t))))

Can anyone tell me what I'm doing wrong??

3
  • Learn to indent your code. You'll notice that the second condition is ignored, as its closing parenthesis goes before the export.
    – choroba
    Commented Jan 22, 2017 at 14:29
  • sorry I was writing from my phone and indent not works well, here it's my real function.
    – rafaelleru
    Commented Jan 22, 2017 at 15:10
  • You may want t consider using ’derived-mode-p’ instead of testing with eq.
    – YoungFrog
    Commented Feb 1, 2017 at 6:37

1 Answer 1

2

First, you don't want to test string-content equality using eq. Use equal instead. Or you can use string-equal, if you are sure that buffer-file-name will return a string in your context.

See the Elisp manual, nodes Equality Predicates and Text Comparison.

Second, consider using function buffer-file-name instead of variable buffer-file-name. Not necessary, but a good habit, IMO. (And you can use it in other contexts, where you pass a BUFFER argument.)

Third, you might need/want to use function buffer-file-truename instead of buffer-file-name.

Only the first is important, probably: You cannot test string content using eq.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.