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??

Drew
  • 75,699
  • 9
  • 109
  • 225
rafaelleru
  • 381
  • 1
  • 13

1 Answers1

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.

Drew
  • 75,699
  • 9
  • 109
  • 225