0

I made a function in Windows Emacs like:

(defun explorer (&optional tex)
  (interactive)
  (let* ((current-path (file-name-directory (buffer-file-name)))
         (file-path-at-point
           (file-name-directory
             (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"))))
  (shell-command
     (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?

3

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 Feb 4 '15 at 7:42
  • thanks, finally i solved the problem with current-prefix-arg. – Leu_Grady Feb 4 '15 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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