Last active
January 1, 2026 16:23
-
-
Save SuperCowProducts/54795e2a7441a5adcd042fe86958d95f to your computer and use it in GitHub Desktop.
[UPDATED 2025] Keyboard shortcuts for color annotations in `pdf-tools` for `emacs`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require 'package) | |
| (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) | |
| ;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities` | |
| ;; and `package-pinned-packages`. Most users will not need or want to do this. | |
| ;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) | |
| (package-initialize) | |
| (blink-cursor-mode -1) | |
| (pdf-tools-install) ;;(pdf-loader-install) ; On demand loading, leads to faster startup time | |
| ;; annotation colours | |
| (defun bms/pdf-annot-colour-gray () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "gray")) | |
| (highlight (color . "gray")) (squiggly (color . "gray")) | |
| (strike-out (color . "gray")) (underline (color . "gray")))) | |
| (message "%s" (propertize "Annotation colour set to gray." 'face '(:foreground "gray")))) | |
| (defun bms/pdf-annot-colour-yellow () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "yellow")) | |
| (highlight (color . "yellow")) (squiggly (color . "yellow")) | |
| (strike-out (color . "yellow")) (underline (color . "yellow")))) | |
| (message "%s" (propertize "Annotation colour set to yellow." 'face '(:foreground "yellow")))) | |
| (defun bms/pdf-annot-colour-pink () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "pink")) | |
| (highlight (color . "pink")) (squiggly (color . "pink")) | |
| (strike-out (color . "pink")) (underline (color . "pink")))) | |
| (message "%s" (propertize "Annotation colour set to pink." 'face '(:foreground "pink")))) | |
| (defun bms/pdf-annot-colour-cyan () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "cyan")) | |
| (highlight (color . "cyan")) (squiggly (color . "cyan")) | |
| (strike-out (color . "cyan")) (underline (color . "cyan")))) | |
| (message "%s" (propertize "Annotation colour set to cyan." 'face '(:foreground "cyan")))) | |
| (defun bms/pdf-annot-colour-blue () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "blue")) | |
| (highlight (color . "blue")) (squiggly (color . "blue")) | |
| (strike-out (color . "blue")) (underline (color . "blue")))) | |
| (message "%s" (propertize "Annotation colour set to blue." 'face '(:foreground "blue")))) | |
| (defun bms/pdf-annot-colour-orange () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "orange")) | |
| (highlight (color . "orange")) (squiggly (color . "orange")) | |
| (strike-out (color . "orange")) (underline (color . "orange")))) | |
| (message "%s" (propertize "Annotation colour set to orange." 'face '(:foreground "orange")))) | |
| (defun bms/pdf-annot-colour-gold () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "gold")) | |
| (highlight (color . "gold")) (squiggly (color . "gold")) | |
| (strike-out (color . "gold")) (underline (color . "gold")))) | |
| (message "%s" (propertize "Annotation colour set to gold." 'face '(:foreground "gold")))) | |
| (defun bms/pdf-annot-colour-green () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "green")) | |
| (highlight (color . "green")) (squiggly (color . "green")) | |
| (strike-out (color . "green")) (underline (color . "green")))) | |
| (message "%s" (propertize "Annotation colour set to green." 'face '(:foreground "green")))) | |
| (defun bms/pdf-annot-colour-red () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "red")) | |
| (highlight (color . "red")) (squiggly (color . "red")) | |
| (strike-out (color . "red")) (underline (color . "red")))) | |
| (message "%s" (propertize "Annotation colour set to red." 'face '(:foreground "red")))) | |
| (defun bms/pdf-annot-colour-purple () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "purple")) | |
| (highlight (color . "purple")) (squiggly (color . "purple")) | |
| (strike-out (color . "purple")) (underline (color . "purple")))) | |
| (message "%s" (propertize "Annotation colour set to purple." 'face '(:foreground "purple")))) | |
| (defun bms/pdf-annot-colour-silver () | |
| (interactive) | |
| (setq pdf-annot-default-annotation-properties | |
| '((t (label . "Alessandro")) (text (icon . "Note") (color . "silver")) | |
| (highlight (color . "silver")) (squiggly (color . "silver")) | |
| (strike-out (color . "silver")) (underline (color . "silver")))) | |
| (message "%s" (propertize "Annotation colour set to silver." 'face '(:foreground "silver")))) | |
| (defun bms/pdf-selection-style-glyph () | |
| (interactive) | |
| (setq pdf-view-selection-style 'glyph) | |
| (message "%s" (propertize "Selection style set to glyph." 'face '(:foreground "gray")))) | |
| (defun bms/pdf-selection-style-word () | |
| (interactive) | |
| (setq pdf-view-selection-style 'word) | |
| (message "%s" (propertize "Selection style set to word." 'face '(:foreground "gray")))) | |
| ;; rebind keys for pdf-tools | |
| (defun bms/pdf-tools-mode-config () | |
| "Set pdf-tools keybindings." | |
| (local-set-key (kbd "a") #'bms/pdf-annot-colour-gray) | |
| (local-set-key (kbd "e") #'bms/pdf-annot-colour-yellow) | |
| (local-set-key (kbd "k") #'bms/pdf-annot-colour-pink) | |
| (local-set-key (kbd "y") #'bms/pdf-annot-colour-cyan) | |
| (local-set-key (kbd "b") #'bms/pdf-annot-colour-blue) | |
| (local-set-key (kbd "o") #'bms/pdf-annot-colour-orange) | |
| (local-set-key (kbd "g") #'bms/pdf-annot-colour-gold) | |
| (local-set-key (kbd "n") #'bms/pdf-annot-colour-green) | |
| (local-set-key (kbd "d") #'bms/pdf-annot-colour-red) | |
| (local-set-key (kbd "p") #'bms/pdf-annot-colour-purple) | |
| (local-set-key (kbd "s") #'bms/pdf-annot-colour-silver) | |
| (local-set-key (kbd ",") #'bms/pdf-selection-style-glyph) | |
| (local-set-key (kbd ".") #'bms/pdf-selection-style-word)) | |
| ;; add to pdf-view-mode-hook | |
| (add-hook 'pdf-view-mode-hook #'bms/pdf-tools-mode-config) | |
| (add-hook 'pdf-outline-minor-mode-hook (lambda () (define-key pdf-outline-minor-mode-map (kbd "o") nil))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment