diff options
| author | Visuwesh <visuweshm@gmail.com> | 2022-10-24 17:10:58 +0530 |
|---|---|---|
| committer | Vedang Manerikar <ved.manerikar@gmail.com> | 2023-01-17 09:02:15 +0530 |
| commit | 2037c52f127f3971e8f8bcd1a8874bcaa4c8f5ba (patch) | |
| tree | 6e0cb6933160d39aa45c3f5ea6408a8664b9e4ec | |
| parent | e55e2ceca7a6091265eadec254c7fad98851a886 (diff) | |
Add a dedicated rotation command and keybinding
We need a dedicated command for rotation since when `pdf-tools`
redisplays the image, the `:rotation` image-property is lost.
Pdf-tools redisplays the images when changing pages, zooming in/out,
setting the slice, etc. so this is essential to have.
A variable is used simply because `pdf-tools` already uses a variable to
keep track of the current scaling.
* lisp/pdf-view.el (pdf-view--current-rotation): Add new variable to
keep track of angle.
(pdf-view-create-page): Account for above.
(pdf-view-mode-map): Add the new command under "R".
(pdf-view-rotate): Add new command.
Fixes: #152
Closes: #165
| -rw-r--r-- | NEWS | 3 | ||||
| -rw-r--r-- | README.org | 2 | ||||
| -rw-r--r-- | lisp/pdf-view.el | 21 |
3 files changed, 26 insertions, 0 deletions
@@ -5,6 +5,9 @@ + This feature enabled us to change the default ~selection-style~ used in ~pdf-tools~ from =GLYPH= to =WORD=. + The change makes highlighting / selecting text *much* snappier. If you want to go back to the old behaviour of selecting by glyph instead of word, or if you want to select a whole line instead, customize ~pdf-view-selection-style~ +- Track rotation of pages and add a command to make rotation of pages easy @vizs #165 + + The new command is bound to =R= in `pdf-view-mode-map`. + ** Functionality fixes and improvements - Fix: Saving a PDF when ~buffer-file-name~ is missing will now prompt for a filename (eg: in EWW) @akater #178 @@ -288,6 +288,8 @@ Note that ~pdf-tools~ renders the PDF as images inside Emacs. This means that al | Trim Margins (set slice to bounding box) | ~s b~ | | Reset Margins | ~s r~ | | Reset Zoom | ~0~ | +| Rotate Page | ~R~ | +|------------------------------------------+-----------------| ** Annotations :PROPERTIES: diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el index 454effa..afca46f 100644 --- a/lisp/pdf-view.el +++ b/lisp/pdf-view.el @@ -226,6 +226,9 @@ regarding display of the region in the later function.") (defvar-local pdf-view--hotspot-functions nil "Alist of hotspot functions.") +(defvar-local pdf-view--current-rotation nil + "Current rotation of the page.") + (defvar-local pdf-view-register-alist nil "Local, dedicated register for PDF positions.") @@ -290,6 +293,8 @@ regarding display of the region in the later function.") (define-key map (kbd "s m") 'pdf-view-set-slice-using-mouse) (define-key map (kbd "s b") 'pdf-view-set-slice-from-bounding-box) (define-key map (kbd "s r") 'pdf-view-reset-slice) + ;; Rotation. + (define-key map (kbd "R") #'pdf-view-rotate) ;; Reconvert (define-key map (kbd "C-c C-c") 'doc-view-mode) (define-key map (kbd "g") 'revert-buffer) @@ -586,6 +591,21 @@ For example, (pdf-view-shrink 1.25) decreases size by 20%." (setq pdf-view-display-size 1.0) (pdf-view-redisplay t)) + +;; * ================================================================== * +;; * Rotation +;; * ================================================================== * +(defun pdf-view-rotate (angle) + "Rotate the current page by ANGLE degrees clockwise. +When called interactively, angle defaults to 90. Moreover, if +called interactively with a prefix argument, then rotate +anti-clockwise." + (interactive (list (if current-prefix-arg -90 90))) + (setq-local pdf-view--current-rotation + (mod (+ (or pdf-view--current-rotation 0) + angle) + 360)) + (pdf-view-redisplay t)) ;; * ================================================================== * @@ -974,6 +994,7 @@ See also `pdf-view-use-imagemagick'." window page size))) (pdf-view-create-image data :width (car size) + :rotation (or pdf-view--current-rotation 0) :map hotspots :pointer 'arrow))) |
