I made a function in Windows Emacs like:

(defun explorer (&optional tex)
  (let* ((current-path (file-name-directory (buffer-file-name)))
             (concat current-path (if (or (ffap-file-at-point) (ffap-url-at-point))
                                (substring (ffap-url-at-point) 5))))))
  (if (equal tex t)
     (shell-command (format "\"C:/Program Files/TeXnicCenter/TeXnicCenter.exe\" %s" (concat (file-name-sans-extension (buffer-file-name)) "\.tex"))))
     (format "explorer.exe %s"
        (convert-standard-filename (or file-path-at-point current-path))) t nil)))

 (bind-key "<f11>" 'explorer)

In my opinion, when I press f11, this function should open window explorer for me, and if I press C-u f11, it should open a LaTeX file of current directory with Texniccenter.exe, but why doesn't it work, it just open the directory?

PS: if there is some other problems of this function, can anyone give me some advice?

1 Answer 1


Optional arguments don't magically get a value when you use C-u unless you tell Emacs to do that.

Have a read of C-hf interactive (see options "p" and "P" in particular), and then see C-hig (elisp) Prefix Command Arguments.

  • Instead of C-h i g ... one can also eval (info "(elisp) Prefix Command Arguments").
    – Adobe
    Commented Feb 4, 2015 at 7:42
  • thanks, finally i solved the problem with current-prefix-arg.
    – Leu_Grady
    Commented Feb 4, 2015 at 9:05

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.