From f5ac4966223f4e5d3dad55d643ecb97c4ffeee2d Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sun, 2 Jul 2017 19:07:19 +0100 Subject: [PATCH] Emacs: Replace init-pdf by pdf-tools --- .emacs.d/init.el | 6 ++-- .emacs.d/lisp/init-dired.el | 4 +-- .emacs.d/lisp/init-org.el | 6 ++-- .emacs.d/lisp/init-pdf.el | 63 ------------------------------------- .emacs.d/lisp/init-tex.el | 16 +++------- 5 files changed, 10 insertions(+), 85 deletions(-) delete mode 100644 .emacs.d/lisp/init-pdf.el diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 1300af5e..e5bad90e 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -204,9 +204,9 @@ e-mail." (with-eval-after-load 'org (require 'init-org)) ;;; PDF -;;; TODO: Replace with pdf-tools package? -(autoload 'pdf-view "init-pdf" nil t) -(autoload 'pdf-compress "init-pdf" nil t) +(nconc package-selected-packages '(pdf-tools)) +(when (require 'pdf-tools nil t) + (pdf-tools-install)) ;;; Perl (defun perl-set-indent-rules () diff --git a/.emacs.d/lisp/init-dired.el b/.emacs.d/lisp/init-dired.el index ace73206..3347c329 100644 --- a/.emacs.d/lisp/init-dired.el +++ b/.emacs.d/lisp/init-dired.el @@ -31,13 +31,11 @@ (require 'dired-x) (setq dired-omit-files "^\\.") -(require 'init-pdf) ; for `pdf-viewer' (setq dired-guess-shell-alist-user (list '("\\.ogg$" "mpv") '("\\.\\(jpe?g\\|png\\|git\\)$" "sxiv") - '("\\.\\(mkv\\|mpe?g\\|avi\\|mp4\\|ogm\\)$" "mpv") - '("\\.pdf$" (concat pdf-viewer " " (mapconcat 'identity pdf-viewer-args " "))))) + '("\\.\\(mkv\\|mpe?g\\|avi\\|mp4\\|ogm\\)$" "mpv"))) (defvar dired-showing-humansize t "If dired is displaying humansize or not.") diff --git a/.emacs.d/lisp/init-org.el b/.emacs.d/lisp/init-org.el index eac01758..c7d3b8ec 100644 --- a/.emacs.d/lisp/init-org.el +++ b/.emacs.d/lisp/init-org.el @@ -18,10 +18,8 @@ ;;; Agendas. (add-to-list 'org-agenda-files "~/personal/todo/todo.org") -;;; Set PDF association in Org-mode (was Evince by default). -(require 'init-pdf) -(setcdr (assoc "\\.pdf\\'" org-file-apps) - (concat pdf-viewer " " (mapconcat 'identity pdf-viewer-args " "))) +;;; Set PDF association in Org-mode (original is 'default). +(setcdr (assoc "\\.pdf\\'" org-file-apps) 'emacs) ;;; Hooks. (dolist (fun '(turn-off-linum turn-off-indent-tabs turn-off-auto-fill)) diff --git a/.emacs.d/lisp/init-pdf.el b/.emacs.d/lisp/init-pdf.el deleted file mode 100644 index 2253a81d..00000000 --- a/.emacs.d/lisp/init-pdf.el +++ /dev/null @@ -1,63 +0,0 @@ -;;; PDF utils - -(defvar pdf-compressor "pdfctl" "PDF compressor.") - -(defvar pdf-viewer "zathura" "PDF viewer.") - -(defvar pdf-viewer-args - '("--fork" - "-x" "emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'") - "List of arguments passed to `pdf-viewer' when called. -You may want to fork the viewer so that it detects when the same -document is launched twice, and persists when Emacs gets closed.\n -For instance with `zathura':\n - zathura --fork\n -We can use\n - emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'\n -to reverse-search a PDF using SyncTeX. Note this can only work -with emacsclient since we need to communicate the command to an -existing instance.") - -;;;###autoload -(defun pdf-compress (&optional file) - "Call `pdf-compessor' over FILE. -If FILE is not provided, use PDF associated to current buffer -filename. If called with universal argument, prompt for filename. -It FILE is not a PDF, the extension is automatically replaced by -.pdf." - (interactive - (list (if (equal current-prefix-arg '(4)) - (expand-file-name (read-file-name "PDF to view: " nil nil t - (concat (file-name-base buffer-file-name) ".pdf")))))) - (let ((pdf (concat - (file-name-sans-extension - (if file file - buffer-file-name)) - ".pdf"))) - (when (and (file-exists-p pdf) (file-writable-p pdf) - (executable-find pdf-compressor)) - (start-process "dummy" nil pdf-compressor "compress" "-i" pdf) - (message "File %s compressed." pdf)))) - -;;;###autoload -(defun pdf-view (&optional file) - "Call `pdf-viewer' over FILE. -If FILE is not provided, use PDF associated to current buffer -filename. If called with universal argument, prompt for filename. -It FILE is not a PDF, the extension is automatically replaced by -.pdf." - (interactive - (list (if (equal current-prefix-arg '(4)) - (expand-file-name (read-file-name "PDF to view: " nil nil t - (concat (file-name-base buffer-file-name) ".pdf")))))) - (let ((pdf (concat - (file-name-sans-extension - (if file file - buffer-file-name)) - ".pdf"))) - (when (and - (file-exists-p pdf) (file-writable-p pdf) - (executable-find pdf-viewer)) - (apply 'start-process "dummy" nil pdf-viewer pdf pdf-viewer-args)))) - -(provide 'init-pdf) diff --git a/.emacs.d/lisp/init-tex.el b/.emacs.d/lisp/init-tex.el index 278ba5ac..9a6c6999 100644 --- a/.emacs.d/lisp/init-tex.el +++ b/.emacs.d/lisp/init-tex.el @@ -84,21 +84,13 @@ This command should be safe, but there is no warranty." (delete-file file) (message "Deleted %S." file))))) -(defun tex-pdf-compress () - "Use `tex-masterfile' variable as default value for `pdf-compress'." - (interactive) - (require 'init-pdf) - (hack-local-variables) - (let ((master (or tex-masterfile buffer-file-name))) - (pdf-compress master))) - (defun tex-pdf-view () - "Use `tex-masterfile' variable as default value for `pdf-view'." + "Find PDF file associated to `tex-masterfile' if set or buffer-filename otherwise." (interactive) - (require 'init-pdf) (hack-local-variables) - (let ((master (or tex-masterfile buffer-file-name))) - (pdf-view master))) + (find-file (concat + (file-name-sans-extension (or tex-masterfile buffer-file-name)) + ".pdf"))) (defun tex-toggle-escape-char () "Make backslash part of the word syntax or not.