I'm using pdftools when displaying pdfs and it would be nice if emacs could bookmark the pdf with the default filename when I kill that buffer. I've got something like this, but it doesn't work.
;; Set a bookmark on kill (add-hook 'kill-buffer-hook `bookmark-set)
I've remarked out all my configuration apart from the add-hook line above. When I open up a pdf file which I want to test with bookmarking on exit I get the following error;
bookmark-buffer-file-name: Buffer not visiting a file or directory Making completion list... [2 times] File Linux-Voice-Issue-027.pdf is large (73.0M), really open? (y or n) y File mode specification error: (error "Buffer not visiting a file or directory") bookmark-buffer-file-name: Buffer not visiting a file or directory
After putting the code 'chen bin' has suggested I'm getting a lot further. However now when I commit a change using Magit I get the following error and the commit buffer doesn't close, although the commit happens.
Type C-c C-c to finish, or C-c C-k to cancel Saving file /home/map7/testgit/.git/COMMIT_EDITMSG... Wrote /home/map7/testgit/.git/COMMIT_EDITMSG string=: Wrong type argument: char-or-string-p, nil Git finished (No files need saving)
I now understand that I also need to test if my buffer file I'm closing has an extension.
(defun kill-buffer-hook-setup () (if (and buffer-file-name (file-name-extension buffer-file-name) (string= (downcase (file-name-extension buffer-file-name)) "pdf") (yes-or-no-p "Set bookmark with current file name?")) (bookmark-set (file-name-nondirectory buffer-file-name) nil))) (add-hook 'kill-buffer-hook 'kill-buffer-hook-setup)