2012-09-27 03:16:35 +00:00
|
|
|
|
;;; image-mode.el --- support for visiting image files -*- lexical-binding: t -*-
|
2005-03-18 00:15:23 +00:00
|
|
|
|
;;
|
2017-01-01 03:14:01 +00:00
|
|
|
|
;; Copyright (C) 2005-2017 Free Software Foundation, Inc.
|
2005-03-18 00:15:23 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Richard Stallman <rms@gnu.org>
|
|
|
|
|
;; Keywords: multimedia
|
2010-08-29 16:17:13 +00:00
|
|
|
|
;; Package: emacs
|
2005-03-18 00:15:23 +00:00
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2005-03-18 00:15:23 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
2005-03-18 00:15:23 +00:00
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-18 00:15:23 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Defines a major mode for visiting image files
|
2016-02-27 17:27:31 +00:00
|
|
|
|
;; that allows conversion between viewing the text of the file,
|
|
|
|
|
;; hex of the file and viewing the file as an image. Viewing the image
|
2005-03-18 00:15:23 +00:00
|
|
|
|
;; works by putting a `display' text-property on the
|
|
|
|
|
;; image data, with the image-data still present underneath; if the
|
|
|
|
|
;; resulting buffer file is saved to another name it will correctly save
|
|
|
|
|
;; the image data to the new file.
|
|
|
|
|
|
2012-09-27 03:16:35 +00:00
|
|
|
|
;; Todo:
|
|
|
|
|
|
|
|
|
|
;; Consolidate with doc-view to make them work on directories of images or on
|
|
|
|
|
;; image files containing various "pages".
|
|
|
|
|
|
2005-03-18 00:15:23 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'image)
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
2005-03-18 00:15:23 +00:00
|
|
|
|
|
2008-02-21 03:27:15 +00:00
|
|
|
|
;;; Image mode window-info management.
|
|
|
|
|
|
2016-12-14 21:36:31 +00:00
|
|
|
|
(defvar-local image-mode-winprops-alist t
|
|
|
|
|
"Alist of windows to window properties.
|
|
|
|
|
Each element has the form (WINDOW . ALIST).
|
|
|
|
|
See `image-mode-winprops'.")
|
2008-02-21 03:27:15 +00:00
|
|
|
|
|
|
|
|
|
(defvar image-mode-new-window-functions nil
|
|
|
|
|
"Special hook run when image data is requested in a new window.
|
|
|
|
|
It is called with one argument, the initial WINPROPS.")
|
|
|
|
|
|
2014-09-18 18:38:05 +00:00
|
|
|
|
;; FIXME this doesn't seem mature yet. Document in manual when it is.
|
|
|
|
|
(defvar image-transform-resize nil
|
|
|
|
|
"The image resize operation.
|
|
|
|
|
Its value should be one of the following:
|
|
|
|
|
- nil, meaning no resizing.
|
|
|
|
|
- `fit-height', meaning to fit the image to the window height.
|
|
|
|
|
- `fit-width', meaning to fit the image to the window width.
|
|
|
|
|
- A number, which is a scale factor (the default size is 1).")
|
|
|
|
|
|
|
|
|
|
(defvar image-transform-scale 1.0
|
|
|
|
|
"The scale factor of the image being displayed.")
|
|
|
|
|
|
|
|
|
|
(defvar image-transform-rotation 0.0
|
|
|
|
|
"Rotation angle for the image in the current Image mode buffer.")
|
|
|
|
|
|
|
|
|
|
(defvar image-transform-right-angle-fudge 0.0001
|
|
|
|
|
"Snap distance to a multiple of a right angle.
|
|
|
|
|
There's no deep theory behind the default value, it should just
|
|
|
|
|
be somewhat larger than ImageMagick's MagickEpsilon.")
|
|
|
|
|
|
2008-05-22 21:27:42 +00:00
|
|
|
|
(defun image-mode-winprops (&optional window cleanup)
|
2008-02-21 03:27:15 +00:00
|
|
|
|
"Return winprops of WINDOW.
|
2012-09-27 03:16:35 +00:00
|
|
|
|
A winprops object has the shape (WINDOW . ALIST).
|
|
|
|
|
WINDOW defaults to `selected-window' if it displays the current buffer, and
|
|
|
|
|
otherwise it defaults to t, used for times when the buffer is not displayed."
|
2008-05-22 21:27:42 +00:00
|
|
|
|
(cond ((null window)
|
2012-09-27 03:16:35 +00:00
|
|
|
|
(setq window
|
|
|
|
|
(if (eq (current-buffer) (window-buffer)) (selected-window) t)))
|
|
|
|
|
((eq window t))
|
2008-05-22 21:27:42 +00:00
|
|
|
|
((not (windowp window))
|
|
|
|
|
(error "Not a window: %s" window)))
|
|
|
|
|
(when cleanup
|
|
|
|
|
(setq image-mode-winprops-alist
|
|
|
|
|
(delq nil (mapcar (lambda (winprop)
|
2013-01-09 22:47:27 +00:00
|
|
|
|
(let ((w (car-safe winprop)))
|
|
|
|
|
(if (or (not (windowp w)) (window-live-p w))
|
|
|
|
|
winprop)))
|
2008-05-22 21:27:42 +00:00
|
|
|
|
image-mode-winprops-alist))))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(let ((winprops (assq window image-mode-winprops-alist)))
|
|
|
|
|
;; For new windows, set defaults from the latest.
|
2013-05-24 17:42:23 +00:00
|
|
|
|
(if winprops
|
|
|
|
|
;; Move window to front.
|
|
|
|
|
(setq image-mode-winprops-alist
|
|
|
|
|
(cons winprops (delq winprops image-mode-winprops-alist)))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(setq winprops (cons window
|
|
|
|
|
(copy-alist (cdar image-mode-winprops-alist))))
|
2013-05-24 17:42:23 +00:00
|
|
|
|
;; Add winprops before running the hook, to avoid inf-loops if the hook
|
|
|
|
|
;; triggers window-configuration-change-hook.
|
|
|
|
|
(setq image-mode-winprops-alist
|
|
|
|
|
(cons winprops image-mode-winprops-alist))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(run-hook-with-args 'image-mode-new-window-functions winprops))
|
|
|
|
|
winprops))
|
|
|
|
|
|
|
|
|
|
(defun image-mode-window-get (prop &optional winprops)
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(declare (gv-setter (lambda (val)
|
|
|
|
|
`(image-mode-window-put ,prop ,val ,winprops))))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(unless (consp winprops) (setq winprops (image-mode-winprops winprops)))
|
|
|
|
|
(cdr (assq prop (cdr winprops))))
|
|
|
|
|
|
|
|
|
|
(defun image-mode-window-put (prop val &optional winprops)
|
|
|
|
|
(unless (consp winprops) (setq winprops (image-mode-winprops winprops)))
|
2014-04-21 14:34:49 +00:00
|
|
|
|
(unless (eq t (car winprops))
|
|
|
|
|
(image-mode-window-put prop val t))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(setcdr winprops (cons (cons prop val)
|
|
|
|
|
(delq (assq prop (cdr winprops)) (cdr winprops)))))
|
|
|
|
|
|
|
|
|
|
(defun image-set-window-vscroll (vscroll)
|
|
|
|
|
(setf (image-mode-window-get 'vscroll) vscroll)
|
|
|
|
|
(set-window-vscroll (selected-window) vscroll))
|
|
|
|
|
|
|
|
|
|
(defun image-set-window-hscroll (ncol)
|
2008-02-21 05:38:30 +00:00
|
|
|
|
(setf (image-mode-window-get 'hscroll) ncol)
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(set-window-hscroll (selected-window) ncol))
|
|
|
|
|
|
|
|
|
|
(defun image-mode-reapply-winprops ()
|
2008-03-26 15:49:03 +00:00
|
|
|
|
;; When set-window-buffer, set hscroll and vscroll to what they were
|
|
|
|
|
;; last time the image was displayed in this window.
|
2013-05-27 00:59:33 +00:00
|
|
|
|
(when (listp image-mode-winprops-alist)
|
|
|
|
|
;; Beware: this call to image-mode-winprops can't be optimized away,
|
|
|
|
|
;; because it not only gets the winprops data but sets it up if needed
|
|
|
|
|
;; (e.g. it's used by doc-view to display the image in a new window).
|
2008-05-22 21:27:42 +00:00
|
|
|
|
(let* ((winprops (image-mode-winprops nil t))
|
2008-03-26 15:49:03 +00:00
|
|
|
|
(hscroll (image-mode-window-get 'hscroll winprops))
|
|
|
|
|
(vscroll (image-mode-window-get 'vscroll winprops)))
|
2013-05-27 00:59:33 +00:00
|
|
|
|
(when (image-get-display-property) ;Only do it if we display an image!
|
|
|
|
|
(if hscroll (set-window-hscroll (selected-window) hscroll))
|
|
|
|
|
(if vscroll (set-window-vscroll (selected-window) vscroll))))))
|
2008-01-29 13:49:05 +00:00
|
|
|
|
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(defun image-mode-setup-winprops ()
|
|
|
|
|
;; Record current scroll settings.
|
|
|
|
|
(unless (listp image-mode-winprops-alist)
|
|
|
|
|
(setq image-mode-winprops-alist nil))
|
|
|
|
|
(add-hook 'window-configuration-change-hook
|
|
|
|
|
'image-mode-reapply-winprops nil t))
|
|
|
|
|
|
|
|
|
|
;;; Image scrolling functions
|
|
|
|
|
|
2008-02-18 04:08:04 +00:00
|
|
|
|
(defun image-get-display-property ()
|
|
|
|
|
(get-char-property (point-min) 'display
|
|
|
|
|
;; There might be different images for different displays.
|
|
|
|
|
(if (eq (window-buffer) (current-buffer))
|
|
|
|
|
(selected-window))))
|
|
|
|
|
|
2008-06-12 03:56:20 +00:00
|
|
|
|
(declare-function image-size "image.c" (spec &optional pixels frame))
|
2016-01-19 23:13:07 +00:00
|
|
|
|
(declare-function xwidget-info "xwidget.c" (xwidget))
|
|
|
|
|
(declare-function xwidget-at "xwidget.el" (pos))
|
2008-06-12 03:56:20 +00:00
|
|
|
|
|
2010-07-17 21:51:04 +00:00
|
|
|
|
(defun image-display-size (spec &optional pixels frame)
|
2011-01-28 19:13:01 +00:00
|
|
|
|
"Wrapper around `image-size', handling slice display properties.
|
|
|
|
|
Like `image-size', the return value is (WIDTH . HEIGHT).
|
|
|
|
|
WIDTH and HEIGHT are in canonical character units if PIXELS is
|
|
|
|
|
nil, and in pixel units if PIXELS is non-nil.
|
|
|
|
|
|
2016-01-19 23:13:07 +00:00
|
|
|
|
If SPEC is an image display property, this function is equivalent to
|
|
|
|
|
`image-size'. If SPEC represents an xwidget object, defer to `xwidget-info'.
|
|
|
|
|
If SPEC is a list of properties containing `image' and `slice' properties,
|
|
|
|
|
return the display size taking the slice property into account. If the list
|
|
|
|
|
contains `image' but not `slice', return the `image-size' of the specified
|
|
|
|
|
image."
|
|
|
|
|
(cond ((eq (car spec) 'xwidget)
|
2016-01-20 00:09:45 +00:00
|
|
|
|
(let ((xwi (xwidget-info (xwidget-at (point-min)))))
|
2016-01-19 23:13:07 +00:00
|
|
|
|
(cons (aref xwi 2) (aref xwi 3))))
|
|
|
|
|
((eq (car spec) 'image)
|
|
|
|
|
(image-size spec pixels frame))
|
|
|
|
|
(t (let ((image (assoc 'image spec))
|
|
|
|
|
(slice (assoc 'slice spec)))
|
|
|
|
|
(cond ((and image slice)
|
|
|
|
|
(if pixels
|
|
|
|
|
(cons (nth 3 slice) (nth 4 slice))
|
|
|
|
|
(cons (/ (float (nth 3 slice)) (frame-char-width frame))
|
|
|
|
|
(/ (float (nth 4 slice))
|
|
|
|
|
(frame-char-height frame)))))
|
|
|
|
|
(image
|
|
|
|
|
(image-size image pixels frame))
|
|
|
|
|
(t
|
|
|
|
|
(error "Invalid image specification: %s" spec)))))))
|
2010-07-17 21:51:04 +00:00
|
|
|
|
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(defun image-forward-hscroll (&optional n)
|
|
|
|
|
"Scroll image in current window to the left by N character widths.
|
|
|
|
|
Stop if the right edge of the image is reached."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(cond ((= n 0) nil)
|
|
|
|
|
((< n 0)
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-hscroll (max 0 (+ (window-hscroll) n))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(t
|
2008-02-18 04:08:04 +00:00
|
|
|
|
(let* ((image (image-get-display-property))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges)))
|
2010-07-17 21:51:04 +00:00
|
|
|
|
(img-width (ceiling (car (image-display-size image)))))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-hscroll (min (max 0 (- img-width win-width))
|
2008-01-29 13:49:05 +00:00
|
|
|
|
(+ n (window-hscroll))))))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
|
|
|
|
(defun image-backward-hscroll (&optional n)
|
|
|
|
|
"Scroll image in current window to the right by N character widths.
|
|
|
|
|
Stop if the left edge of the image is reached."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(image-forward-hscroll (- n)))
|
|
|
|
|
|
2011-09-11 02:31:21 +00:00
|
|
|
|
(defun image-next-line (n)
|
2007-05-24 23:12:53 +00:00
|
|
|
|
"Scroll image in current window upward by N lines.
|
|
|
|
|
Stop if the bottom edge of the image is reached."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(cond ((= n 0) nil)
|
|
|
|
|
((< n 0)
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-vscroll (max 0 (+ (window-vscroll) n))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(t
|
2008-02-18 04:08:04 +00:00
|
|
|
|
(let* ((image (image-get-display-property))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(edges (window-inside-edges))
|
|
|
|
|
(win-height (- (nth 3 edges) (nth 1 edges)))
|
2010-07-17 21:51:04 +00:00
|
|
|
|
(img-height (ceiling (cdr (image-display-size image)))))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-vscroll (min (max 0 (- img-height win-height))
|
2008-01-29 13:49:05 +00:00
|
|
|
|
(+ n (window-vscroll))))))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
|
|
|
|
(defun image-previous-line (&optional n)
|
|
|
|
|
"Scroll image in current window downward by N lines.
|
|
|
|
|
Stop if the top edge of the image is reached."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(image-next-line (- n)))
|
|
|
|
|
|
|
|
|
|
(defun image-scroll-up (&optional n)
|
|
|
|
|
"Scroll image in current window upward by N lines.
|
|
|
|
|
Stop if the bottom edge of the image is reached.
|
|
|
|
|
If ARG is omitted or nil, scroll upward by a near full screen.
|
|
|
|
|
A near full screen is `next-screen-context-lines' less than a full screen.
|
|
|
|
|
Negative ARG means scroll downward.
|
|
|
|
|
If ARG is the atom `-', scroll downward by nearly full screen.
|
|
|
|
|
When calling from a program, supply as argument a number, nil, or `-'."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(cond ((null n)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-height (- (nth 3 edges) (nth 1 edges))))
|
|
|
|
|
(image-next-line
|
|
|
|
|
(max 0 (- win-height next-screen-context-lines)))))
|
|
|
|
|
((eq n '-)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-height (- (nth 3 edges) (nth 1 edges))))
|
|
|
|
|
(image-next-line
|
|
|
|
|
(min 0 (- next-screen-context-lines win-height)))))
|
|
|
|
|
(t (image-next-line (prefix-numeric-value n)))))
|
|
|
|
|
|
|
|
|
|
(defun image-scroll-down (&optional n)
|
2008-02-01 01:43:36 +00:00
|
|
|
|
"Scroll image in current window downward by N lines.
|
2007-05-24 23:12:53 +00:00
|
|
|
|
Stop if the top edge of the image is reached.
|
|
|
|
|
If ARG is omitted or nil, scroll downward by a near full screen.
|
|
|
|
|
A near full screen is `next-screen-context-lines' less than a full screen.
|
|
|
|
|
Negative ARG means scroll upward.
|
|
|
|
|
If ARG is the atom `-', scroll upward by nearly full screen.
|
|
|
|
|
When calling from a program, supply as argument a number, nil, or `-'."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(cond ((null n)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-height (- (nth 3 edges) (nth 1 edges))))
|
|
|
|
|
(image-next-line
|
|
|
|
|
(min 0 (- next-screen-context-lines win-height)))))
|
|
|
|
|
((eq n '-)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-height (- (nth 3 edges) (nth 1 edges))))
|
|
|
|
|
(image-next-line
|
|
|
|
|
(max 0 (- win-height next-screen-context-lines)))))
|
|
|
|
|
(t (image-next-line (- (prefix-numeric-value n))))))
|
|
|
|
|
|
2016-12-16 02:59:15 +00:00
|
|
|
|
(defun image-scroll-left (&optional n)
|
|
|
|
|
"Scroll image in current window leftward by N character widths.
|
|
|
|
|
Stop if the right edge of the image is reached.
|
|
|
|
|
If ARG is omitted or nil, scroll leftward by a near full screen.
|
|
|
|
|
A near full screen is 2 columns less than a full screen.
|
|
|
|
|
Negative ARG means scroll rightward.
|
|
|
|
|
If ARG is the atom `-', scroll rightward by nearly full screen.
|
|
|
|
|
When calling from a program, supply as argument a number, nil, or `-'."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(cond ((null n)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges))))
|
|
|
|
|
(image-forward-hscroll
|
|
|
|
|
(max 0 (- win-width 2)))))
|
|
|
|
|
((eq n '-)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges))))
|
|
|
|
|
(image-forward-hscroll
|
|
|
|
|
(min 0 (- 2 win-width)))))
|
|
|
|
|
(t (image-forward-hscroll (prefix-numeric-value n)))))
|
|
|
|
|
|
|
|
|
|
(defun image-scroll-right (&optional n)
|
|
|
|
|
"Scroll image in current window rightward by N character widths.
|
|
|
|
|
Stop if the left edge of the image is reached.
|
|
|
|
|
If ARG is omitted or nil, scroll downward by a near full screen.
|
|
|
|
|
A near full screen is 2 less than a full screen.
|
|
|
|
|
Negative ARG means scroll leftward.
|
|
|
|
|
If ARG is the atom `-', scroll leftward by nearly full screen.
|
|
|
|
|
When calling from a program, supply as argument a number, nil, or `-'."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(cond ((null n)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges))))
|
|
|
|
|
(image-forward-hscroll
|
|
|
|
|
(min 0 (- 2 win-width)))))
|
|
|
|
|
((eq n '-)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges))))
|
|
|
|
|
(image-forward-hscroll
|
|
|
|
|
(max 0 (- win-width 2)))))
|
|
|
|
|
(t (image-forward-hscroll (- (prefix-numeric-value n))))))
|
|
|
|
|
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(defun image-bol (arg)
|
|
|
|
|
"Scroll horizontally to the left edge of the image in the current window.
|
|
|
|
|
With argument ARG not nil or 1, move forward ARG - 1 lines first,
|
|
|
|
|
stopping if the top or bottom edge of the image is reached."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(and arg
|
|
|
|
|
(/= (setq arg (prefix-numeric-value arg)) 1)
|
|
|
|
|
(image-next-line (- arg 1)))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-hscroll 0))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
|
|
|
|
(defun image-eol (arg)
|
|
|
|
|
"Scroll horizontally to the right edge of the image in the current window.
|
|
|
|
|
With argument ARG not nil or 1, move forward ARG - 1 lines first,
|
|
|
|
|
stopping if the top or bottom edge of the image is reached."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(and arg
|
|
|
|
|
(/= (setq arg (prefix-numeric-value arg)) 1)
|
|
|
|
|
(image-next-line (- arg 1)))
|
2008-02-18 04:08:04 +00:00
|
|
|
|
(let* ((image (image-get-display-property))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges)))
|
2010-07-17 21:51:04 +00:00
|
|
|
|
(img-width (ceiling (car (image-display-size image)))))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-hscroll (max 0 (- img-width win-width)))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
|
|
|
|
(defun image-bob ()
|
|
|
|
|
"Scroll to the top-left corner of the image in the current window."
|
|
|
|
|
(interactive)
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-hscroll 0)
|
|
|
|
|
(image-set-window-vscroll 0))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
|
|
|
|
(defun image-eob ()
|
|
|
|
|
"Scroll to the bottom-right corner of the image in the current window."
|
|
|
|
|
(interactive)
|
2008-02-18 04:08:04 +00:00
|
|
|
|
(let* ((image (image-get-display-property))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(edges (window-inside-edges))
|
|
|
|
|
(win-width (- (nth 2 edges) (nth 0 edges)))
|
2010-07-17 21:51:04 +00:00
|
|
|
|
(img-width (ceiling (car (image-display-size image))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(win-height (- (nth 3 edges) (nth 1 edges)))
|
2010-07-17 21:51:04 +00:00
|
|
|
|
(img-height (ceiling (cdr (image-display-size image)))))
|
2008-02-21 03:27:15 +00:00
|
|
|
|
(image-set-window-hscroll (max 0 (- img-width win-width)))
|
|
|
|
|
(image-set-window-vscroll (max 0 (- img-height win-height)))))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
2008-04-03 02:19:23 +00:00
|
|
|
|
;; Adjust frame and image size.
|
|
|
|
|
|
2013-01-19 10:34:07 +00:00
|
|
|
|
(defun image-mode-fit-frame (&optional frame toggle)
|
|
|
|
|
"Fit FRAME to the current image.
|
|
|
|
|
If FRAME is omitted or nil, it defaults to the selected frame.
|
|
|
|
|
All other windows on the frame are deleted.
|
|
|
|
|
|
|
|
|
|
If called interactively, or if TOGGLE is non-nil, toggle between
|
|
|
|
|
fitting FRAME to the current image and restoring the size and
|
|
|
|
|
window configuration prior to the last `image-mode-fit-frame'
|
|
|
|
|
call."
|
|
|
|
|
(interactive (list nil t))
|
|
|
|
|
(let* ((buffer (current-buffer))
|
2008-04-03 02:19:23 +00:00
|
|
|
|
(display (image-get-display-property))
|
2013-01-19 10:34:07 +00:00
|
|
|
|
(size (image-display-size display))
|
|
|
|
|
(saved (frame-parameter frame 'image-mode-saved-params))
|
|
|
|
|
(window-configuration (current-window-configuration frame))
|
|
|
|
|
(width (frame-width frame))
|
|
|
|
|
(height (frame-height frame)))
|
|
|
|
|
(with-selected-frame (or frame (selected-frame))
|
|
|
|
|
(if (and toggle saved
|
|
|
|
|
(= (caar saved) width)
|
|
|
|
|
(= (cdar saved) height))
|
|
|
|
|
(progn
|
|
|
|
|
(set-frame-width frame (car (nth 1 saved)))
|
|
|
|
|
(set-frame-height frame (cdr (nth 1 saved)))
|
|
|
|
|
(set-window-configuration (nth 2 saved))
|
|
|
|
|
(set-frame-parameter frame 'image-mode-saved-params nil))
|
|
|
|
|
(delete-other-windows)
|
|
|
|
|
(switch-to-buffer buffer t t)
|
|
|
|
|
(let* ((edges (window-inside-edges))
|
|
|
|
|
(inner-width (- (nth 2 edges) (nth 0 edges)))
|
|
|
|
|
(inner-height (- (nth 3 edges) (nth 1 edges))))
|
|
|
|
|
(set-frame-width frame (+ (ceiling (car size))
|
|
|
|
|
width (- inner-width)))
|
|
|
|
|
(set-frame-height frame (+ (ceiling (cdr size))
|
|
|
|
|
height (- inner-height)))
|
|
|
|
|
;; The frame size after the above `set-frame-*' calls may
|
|
|
|
|
;; differ from what we specified, due to window manager
|
|
|
|
|
;; interference. We have to call `frame-width' and
|
|
|
|
|
;; `frame-height' to get the actual results.
|
|
|
|
|
(set-frame-parameter frame 'image-mode-saved-params
|
|
|
|
|
(list (cons (frame-width)
|
|
|
|
|
(frame-height))
|
|
|
|
|
(cons width height)
|
|
|
|
|
window-configuration)))))))
|
2008-04-03 02:19:23 +00:00
|
|
|
|
|
2007-05-24 23:12:53 +00:00
|
|
|
|
;;; Image Mode setup
|
|
|
|
|
|
2013-05-27 00:59:33 +00:00
|
|
|
|
(defvar-local image-type nil
|
2011-04-09 19:57:47 +00:00
|
|
|
|
"The image type for the current Image mode buffer.")
|
2007-08-28 22:32:07 +00:00
|
|
|
|
|
2013-02-20 07:57:33 +00:00
|
|
|
|
(defvar-local image-multi-frame nil
|
|
|
|
|
"Non-nil if image for the current Image mode buffer has multiple frames.")
|
|
|
|
|
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(defvar image-mode-previous-major-mode nil
|
|
|
|
|
"Internal variable to keep the previous non-image major mode.")
|
|
|
|
|
|
2005-03-18 00:15:23 +00:00
|
|
|
|
(defvar image-mode-map
|
2016-04-24 15:21:18 +00:00
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(define-key map "\C-c\C-c" 'image-toggle-display)
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(define-key map "\C-c\C-x" 'image-toggle-hex-display)
|
2008-06-04 05:58:33 +00:00
|
|
|
|
(define-key map (kbd "SPC") 'image-scroll-up)
|
2013-02-13 08:28:47 +00:00
|
|
|
|
(define-key map (kbd "S-SPC") 'image-scroll-down)
|
2008-06-04 05:58:33 +00:00
|
|
|
|
(define-key map (kbd "DEL") 'image-scroll-down)
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(define-key map (kbd "RET") 'image-toggle-animation)
|
2013-02-16 03:29:39 +00:00
|
|
|
|
(define-key map "F" 'image-goto-frame)
|
|
|
|
|
(define-key map "f" 'image-next-frame)
|
|
|
|
|
(define-key map "b" 'image-previous-frame)
|
2013-01-19 15:22:38 +00:00
|
|
|
|
(define-key map "n" 'image-next-file)
|
|
|
|
|
(define-key map "p" 'image-previous-file)
|
2013-08-16 06:33:08 +00:00
|
|
|
|
(define-key map "a+" 'image-increase-speed)
|
|
|
|
|
(define-key map "a-" 'image-decrease-speed)
|
|
|
|
|
(define-key map "a0" 'image-reset-speed)
|
|
|
|
|
(define-key map "ar" 'image-reverse-speed)
|
2015-02-04 20:02:14 +00:00
|
|
|
|
(define-key map "k" 'image-kill-buffer)
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(define-key map [remap forward-char] 'image-forward-hscroll)
|
|
|
|
|
(define-key map [remap backward-char] 'image-backward-hscroll)
|
2010-06-14 03:19:46 +00:00
|
|
|
|
(define-key map [remap right-char] 'image-forward-hscroll)
|
|
|
|
|
(define-key map [remap left-char] 'image-backward-hscroll)
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(define-key map [remap previous-line] 'image-previous-line)
|
|
|
|
|
(define-key map [remap next-line] 'image-next-line)
|
|
|
|
|
(define-key map [remap scroll-up] 'image-scroll-up)
|
|
|
|
|
(define-key map [remap scroll-down] 'image-scroll-down)
|
2010-04-14 00:33:32 +00:00
|
|
|
|
(define-key map [remap scroll-up-command] 'image-scroll-up)
|
|
|
|
|
(define-key map [remap scroll-down-command] 'image-scroll-down)
|
2016-12-16 02:59:15 +00:00
|
|
|
|
(define-key map [remap scroll-left] 'image-scroll-left)
|
|
|
|
|
(define-key map [remap scroll-right] 'image-scroll-right)
|
2007-05-24 23:12:53 +00:00
|
|
|
|
(define-key map [remap move-beginning-of-line] 'image-bol)
|
|
|
|
|
(define-key map [remap move-end-of-line] 'image-eol)
|
|
|
|
|
(define-key map [remap beginning-of-buffer] 'image-bob)
|
|
|
|
|
(define-key map [remap end-of-buffer] 'image-eob)
|
2013-02-16 19:20:21 +00:00
|
|
|
|
(easy-menu-define image-mode-menu map "Menu for Image mode."
|
|
|
|
|
'("Image"
|
|
|
|
|
["Show as Text" image-toggle-display :active t
|
|
|
|
|
:help "Show image as text"]
|
2016-02-27 17:27:31 +00:00
|
|
|
|
["Show as Hex" image-toggle-hex-display :active t
|
|
|
|
|
:help "Show image as hex"]
|
2013-02-16 19:20:21 +00:00
|
|
|
|
"--"
|
|
|
|
|
["Fit to Window Height" image-transform-fit-to-height
|
|
|
|
|
:visible (eq image-type 'imagemagick)
|
|
|
|
|
:help "Resize image to match the window height"]
|
|
|
|
|
["Fit to Window Width" image-transform-fit-to-width
|
|
|
|
|
:visible (eq image-type 'imagemagick)
|
|
|
|
|
:help "Resize image to match the window width"]
|
|
|
|
|
["Rotate Image..." image-transform-set-rotation
|
|
|
|
|
:visible (eq image-type 'imagemagick)
|
|
|
|
|
:help "Rotate the image"]
|
2014-08-12 14:16:45 +00:00
|
|
|
|
["Reset Transformations" image-transform-reset
|
|
|
|
|
:visible (eq image-type 'imagemagick)
|
|
|
|
|
:help "Reset all image transformations"]
|
2013-02-16 19:20:21 +00:00
|
|
|
|
"--"
|
2013-02-17 00:50:41 +00:00
|
|
|
|
["Show Thumbnails"
|
|
|
|
|
(lambda ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(image-dired default-directory))
|
|
|
|
|
:active default-directory
|
|
|
|
|
:help "Show thumbnails for all images in this directory"]
|
|
|
|
|
["Next Image" image-next-file :active buffer-file-name
|
2013-02-16 19:20:21 +00:00
|
|
|
|
:help "Move to next image in this directory"]
|
2013-02-17 00:50:41 +00:00
|
|
|
|
["Previous Image" image-previous-file :active buffer-file-name
|
2013-02-16 19:20:21 +00:00
|
|
|
|
:help "Move to previous image in this directory"]
|
|
|
|
|
"--"
|
2014-08-12 14:16:45 +00:00
|
|
|
|
["Fit Frame to Image" image-mode-fit-frame :active t
|
|
|
|
|
:help "Resize frame to match image"]
|
|
|
|
|
"--"
|
2013-02-16 19:20:21 +00:00
|
|
|
|
["Animate Image" image-toggle-animation :style toggle
|
|
|
|
|
:selected (let ((image (image-get-display-property)))
|
|
|
|
|
(and image (image-animate-timer image)))
|
2013-02-20 07:57:33 +00:00
|
|
|
|
:active image-multi-frame
|
2013-02-16 19:20:21 +00:00
|
|
|
|
:help "Toggle image animation"]
|
|
|
|
|
["Loop Animation"
|
|
|
|
|
(lambda () (interactive)
|
|
|
|
|
(setq image-animate-loop (not image-animate-loop))
|
|
|
|
|
;; FIXME this is a hacky way to make it affect a currently
|
|
|
|
|
;; animating image.
|
|
|
|
|
(when (let ((image (image-get-display-property)))
|
|
|
|
|
(and image (image-animate-timer image)))
|
|
|
|
|
(image-toggle-animation)
|
|
|
|
|
(image-toggle-animation)))
|
|
|
|
|
:style toggle :selected image-animate-loop
|
2013-02-20 07:57:33 +00:00
|
|
|
|
:active image-multi-frame
|
2013-08-16 06:33:08 +00:00
|
|
|
|
:help "Animate images once, or forever?"]
|
|
|
|
|
["Reverse Animation" image-reverse-speed
|
|
|
|
|
:style toggle :selected (let ((image (image-get-display-property)))
|
|
|
|
|
(and image (<
|
|
|
|
|
(image-animate-get-speed image)
|
|
|
|
|
0)))
|
|
|
|
|
:active image-multi-frame
|
|
|
|
|
:help "Reverse direction of this image's animation?"]
|
|
|
|
|
["Speed Up Animation" image-increase-speed
|
|
|
|
|
:active image-multi-frame
|
|
|
|
|
:help "Speed up this image's animation"]
|
|
|
|
|
["Slow Down Animation" image-decrease-speed
|
|
|
|
|
:active image-multi-frame
|
|
|
|
|
:help "Slow down this image's animation"]
|
|
|
|
|
["Reset Animation Speed" image-reset-speed
|
|
|
|
|
:active image-multi-frame
|
|
|
|
|
:help "Reset the speed of this image's animation"]
|
2013-02-20 07:57:33 +00:00
|
|
|
|
["Next Frame" image-next-frame :active image-multi-frame
|
2013-02-16 19:20:21 +00:00
|
|
|
|
:help "Show the next frame of this image"]
|
2013-02-20 07:57:33 +00:00
|
|
|
|
["Previous Frame" image-previous-frame :active image-multi-frame
|
2013-02-16 19:20:21 +00:00
|
|
|
|
:help "Show the previous frame of this image"]
|
2013-02-20 07:57:33 +00:00
|
|
|
|
["Goto Frame..." image-goto-frame :active image-multi-frame
|
2013-02-16 19:20:21 +00:00
|
|
|
|
:help "Show a specific frame of this image"]
|
|
|
|
|
))
|
2016-04-24 15:21:18 +00:00
|
|
|
|
(make-composed-keymap (list map image-map) special-mode-map))
|
2011-04-09 19:57:47 +00:00
|
|
|
|
"Mode keymap for `image-mode'.")
|
2007-05-24 23:12:53 +00:00
|
|
|
|
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(defvar image-minor-mode-map
|
2005-03-18 00:15:23 +00:00
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map "\C-c\C-c" 'image-toggle-display)
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(define-key map "\C-c\C-x" 'image-toggle-hex-display)
|
2005-03-18 00:15:23 +00:00
|
|
|
|
map)
|
2011-04-09 19:57:47 +00:00
|
|
|
|
"Mode keymap for `image-minor-mode'.")
|
2005-03-18 00:15:23 +00:00
|
|
|
|
|
2008-03-07 05:44:37 +00:00
|
|
|
|
(defvar bookmark-make-record-function)
|
2008-01-04 03:12:43 +00:00
|
|
|
|
|
2010-02-05 22:36:20 +00:00
|
|
|
|
(put 'image-mode 'mode-class 'special)
|
|
|
|
|
|
2005-03-18 00:15:23 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun image-mode ()
|
|
|
|
|
"Major mode for image files.
|
2016-02-27 17:27:31 +00:00
|
|
|
|
You can use \\<image-mode-map>\\[image-toggle-display] or \\<image-mode-map>\\[image-toggle-hex-display]
|
|
|
|
|
to toggle between display as an image and display as text or hex.
|
2013-08-16 06:33:08 +00:00
|
|
|
|
|
|
|
|
|
Key bindings:
|
|
|
|
|
\\{image-mode-map}"
|
2005-03-18 00:15:23 +00:00
|
|
|
|
(interactive)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(condition-case err
|
|
|
|
|
(progn
|
|
|
|
|
(unless (display-images-p)
|
|
|
|
|
(error "Display does not support images"))
|
|
|
|
|
|
|
|
|
|
(kill-all-local-variables)
|
|
|
|
|
(setq major-mode 'image-mode)
|
|
|
|
|
|
|
|
|
|
(if (not (image-get-display-property))
|
|
|
|
|
(progn
|
|
|
|
|
(image-toggle-display-image)
|
|
|
|
|
;; If attempt to display the image fails.
|
|
|
|
|
(if (not (image-get-display-property))
|
|
|
|
|
(error "Invalid image")))
|
|
|
|
|
;; Set next vars when image is already displayed but local
|
|
|
|
|
;; variables were cleared by kill-all-local-variables
|
|
|
|
|
(setq cursor-type nil truncate-lines t
|
|
|
|
|
image-type (plist-get (cdr (image-get-display-property)) :type)))
|
|
|
|
|
|
|
|
|
|
(setq mode-name (if image-type (format "Image[%s]" image-type) "Image"))
|
2008-07-30 13:35:50 +00:00
|
|
|
|
(use-local-map image-mode-map)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
|
|
|
|
|
;; Use our own bookmarking function for images.
|
2013-05-27 00:59:33 +00:00
|
|
|
|
(setq-local bookmark-make-record-function
|
|
|
|
|
#'image-bookmark-make-record)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
|
|
|
|
|
;; Keep track of [vh]scroll when switching buffers
|
|
|
|
|
(image-mode-setup-winprops)
|
|
|
|
|
|
|
|
|
|
(add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
|
2010-05-25 16:03:53 +00:00
|
|
|
|
(add-hook 'after-revert-hook 'image-after-revert-hook nil t)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(run-mode-hooks 'image-mode-hook)
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(let ((image (image-get-display-property))
|
|
|
|
|
(msg1 (substitute-command-keys
|
2016-02-27 17:27:31 +00:00
|
|
|
|
"Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as "))
|
2013-02-16 01:58:20 +00:00
|
|
|
|
animated)
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(cond
|
|
|
|
|
((null image)
|
|
|
|
|
(message "%s" (concat msg1 "an image.")))
|
2013-02-16 19:56:50 +00:00
|
|
|
|
((setq animated (image-multi-frame-p image))
|
2013-02-20 07:57:33 +00:00
|
|
|
|
(setq image-multi-frame t
|
2013-02-16 01:58:20 +00:00
|
|
|
|
mode-line-process
|
2013-02-22 01:34:06 +00:00
|
|
|
|
`(:eval
|
|
|
|
|
(concat " "
|
|
|
|
|
(propertize
|
|
|
|
|
(format "[%s/%s]"
|
|
|
|
|
(1+ (image-current-frame ',image))
|
|
|
|
|
,(car animated))
|
|
|
|
|
'help-echo "Frames
|
|
|
|
|
mouse-1: Next frame
|
|
|
|
|
mouse-3: Previous frame"
|
|
|
|
|
'mouse-face 'mode-line-highlight
|
|
|
|
|
'local-map
|
|
|
|
|
'(keymap
|
|
|
|
|
(mode-line
|
|
|
|
|
keymap
|
|
|
|
|
(down-mouse-1 . image-next-frame)
|
|
|
|
|
(down-mouse-3 . image-previous-frame)))))))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(message "%s"
|
2013-02-16 19:56:50 +00:00
|
|
|
|
(concat msg1 "text. This image has multiple frames.")))
|
|
|
|
|
;;; (substitute-command-keys
|
|
|
|
|
;;; "\\[image-toggle-animation] to animate."))))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(t
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(message "%s" (concat msg1 "text or hex."))))))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(error
|
|
|
|
|
(image-mode-as-text)
|
|
|
|
|
(funcall
|
|
|
|
|
(if (called-interactively-p 'any) 'error 'message)
|
|
|
|
|
"Cannot display image: %s" (cdr err)))))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
|
2005-03-25 19:57:21 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(define-minor-mode image-minor-mode
|
Fix minor mode docstrings for the new meaning of a nil ARG.
* abbrev.el (abbrev-mode):
* allout.el (allout-mode):
* autoinsert.el (auto-insert-mode):
* autoarg.el (autoarg-mode, autoarg-kp-mode):
* autorevert.el (auto-revert-mode, auto-revert-tail-mode)
(global-auto-revert-mode):
* battery.el (display-battery-mode):
* composite.el (global-auto-composition-mode)
(auto-composition-mode):
* delsel.el (delete-selection-mode):
* desktop.el (desktop-save-mode):
* dired-x.el (dired-omit-mode):
* dirtrack.el (dirtrack-mode):
* doc-view.el (doc-view-minor-mode):
* double.el (double-mode):
* electric.el (electric-indent-mode, electric-pair-mode):
* emacs-lock.el (emacs-lock-mode):
* epa-hook.el (auto-encryption-mode):
* follow.el (follow-mode):
* font-core.el (font-lock-mode):
* frame.el (auto-raise-mode, auto-lower-mode, blink-cursor-mode):
* help.el (temp-buffer-resize-mode):
* hilit-chg.el (highlight-changes-mode)
(highlight-changes-visible-mode):
* hi-lock.el (hi-lock-mode):
* hl-line.el (hl-line-mode, global-hl-line-mode):
* icomplete.el (icomplete-mode):
* ido.el (ido-everywhere):
* image-file.el (auto-image-file-mode):
* image-mode.el (image-minor-mode):
* iswitchb.el (iswitchb-mode):
* jka-cmpr-hook.el (auto-compression-mode):
* linum.el (linum-mode):
* longlines.el (longlines-mode):
* master.el (master-mode):
* mb-depth.el (minibuffer-depth-indicate-mode):
* menu-bar.el (menu-bar-mode):
* minibuf-eldef.el (minibuffer-electric-default-mode):
* mouse-sel.el (mouse-sel-mode):
* msb.el (msb-mode):
* mwheel.el (mouse-wheel-mode):
* outline.el (outline-minor-mode):
* paren.el (show-paren-mode):
* recentf.el (recentf-mode):
* reveal.el (reveal-mode, global-reveal-mode):
* rfn-eshadow.el (file-name-shadow-mode):
* ruler-mode.el (ruler-mode):
* savehist.el (savehist-mode):
* scroll-all.el (scroll-all-mode):
* scroll-bar.el (scroll-bar-mode):
* server.el (server-mode):
* shell.el (shell-dirtrack-mode):
* simple.el (auto-fill-mode, transient-mark-mode)
(visual-line-mode, overwrite-mode, binary-overwrite-mode)
(line-number-mode, column-number-mode, size-indication-mode)
(auto-save-mode, normal-erase-is-backspace-mode, visible-mode):
* strokes.el (strokes-mode):
* time.el (display-time-mode):
* t-mouse.el (gpm-mouse-mode):
* tool-bar.el (tool-bar-mode):
* tooltip.el (tooltip-mode):
* type-break.el (type-break-mode-line-message-mode)
(type-break-query-mode):
* view.el (view-mode):
* whitespace.el (whitespace-mode, whitespace-newline-mode)
(global-whitespace-mode, global-whitespace-newline-mode):
* xt-mouse.el (xterm-mouse-mode): Doc fix.
* emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Fix
autogenerated docstring.
2011-10-19 12:54:24 +00:00
|
|
|
|
"Toggle Image minor mode in this buffer.
|
|
|
|
|
With a prefix argument ARG, enable Image minor mode if ARG is
|
|
|
|
|
positive, and disable it otherwise. If called from Lisp, enable
|
|
|
|
|
the mode if ARG is omitted or nil.
|
|
|
|
|
|
|
|
|
|
Image minor mode provides the key \\<image-mode-map>\\[image-toggle-display],
|
|
|
|
|
to switch back to `image-mode' and display an image file as the
|
|
|
|
|
actual image."
|
2009-12-04 21:43:07 +00:00
|
|
|
|
nil (:eval (if image-type (format " Image[%s]" image-type) " Image"))
|
|
|
|
|
image-minor-mode-map
|
2005-03-25 19:57:21 +00:00
|
|
|
|
:group 'image
|
|
|
|
|
:version "22.1"
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(if image-minor-mode
|
|
|
|
|
(add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)))
|
2005-03-25 19:57:21 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(defun image-mode-to-text ()
|
2009-12-04 21:43:07 +00:00
|
|
|
|
"Set a non-image mode as major mode in combination with image minor mode.
|
2016-02-27 17:27:31 +00:00
|
|
|
|
A non-mage major mode found from `auto-mode-alist' or fundamental mode
|
|
|
|
|
displays an image file as text."
|
2009-12-04 21:43:07 +00:00
|
|
|
|
;; image-mode-as-text = normal-mode + image-minor-mode
|
|
|
|
|
(let ((previous-image-type image-type)) ; preserve `image-type'
|
|
|
|
|
(if image-mode-previous-major-mode
|
|
|
|
|
;; Restore previous major mode that was already found by this
|
|
|
|
|
;; function and cached in `image-mode-previous-major-mode'
|
|
|
|
|
(funcall image-mode-previous-major-mode)
|
|
|
|
|
(let ((auto-mode-alist
|
|
|
|
|
(delq nil (mapcar
|
|
|
|
|
(lambda (elt)
|
|
|
|
|
(unless (memq (or (car-safe (cdr elt)) (cdr elt))
|
|
|
|
|
'(image-mode image-mode-maybe image-mode-as-text))
|
|
|
|
|
elt))
|
|
|
|
|
auto-mode-alist)))
|
|
|
|
|
(magic-fallback-mode-alist
|
|
|
|
|
(delq nil (mapcar
|
|
|
|
|
(lambda (elt)
|
|
|
|
|
(unless (memq (or (car-safe (cdr elt)) (cdr elt))
|
|
|
|
|
'(image-mode image-mode-maybe image-mode-as-text))
|
|
|
|
|
elt))
|
|
|
|
|
magic-fallback-mode-alist))))
|
|
|
|
|
(normal-mode)
|
2013-05-27 00:59:33 +00:00
|
|
|
|
(setq-local image-mode-previous-major-mode major-mode)))
|
2009-12-04 21:43:07 +00:00
|
|
|
|
;; Restore `image-type' after `kill-all-local-variables' in `normal-mode'.
|
|
|
|
|
(setq image-type previous-image-type)
|
|
|
|
|
;; Enable image minor mode with `C-c C-c'.
|
|
|
|
|
(image-minor-mode 1)
|
|
|
|
|
;; Show the image file as text.
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(image-toggle-display-text)))
|
|
|
|
|
|
|
|
|
|
(defun image-mode-as-hex ()
|
|
|
|
|
"Set a non-image mode as major mode in combination with image minor mode.
|
|
|
|
|
A non-mage major mode found from `auto-mode-alist' or fundamental mode
|
|
|
|
|
displays an image file as hex. `image-minor-mode' provides the key
|
|
|
|
|
\\<image-mode-map>\\[image-toggle-hex-display] to switch back to `image-mode'
|
|
|
|
|
to display an image file as the actual image.
|
|
|
|
|
|
|
|
|
|
You can use `image-mode-as-hex' in `auto-mode-alist' when you want to
|
|
|
|
|
to display an image file as hex initially.
|
|
|
|
|
|
|
|
|
|
See commands `image-mode' and `image-minor-mode' for more information
|
|
|
|
|
on these modes."
|
|
|
|
|
(interactive)
|
|
|
|
|
(image-mode-to-text)
|
|
|
|
|
;; Turn on hexl-mode
|
|
|
|
|
(hexl-mode)
|
|
|
|
|
(message "%s" (concat
|
|
|
|
|
(substitute-command-keys
|
|
|
|
|
"Type \\[image-toggle-hex-display] or \\[image-toggle-display] to view the image as ")
|
|
|
|
|
(if (image-get-display-property)
|
|
|
|
|
"hex" "an image or text") ".")))
|
|
|
|
|
|
|
|
|
|
(defun image-mode-as-text ()
|
|
|
|
|
"Set a non-image mode as major mode in combination with image minor mode.
|
|
|
|
|
A non-image major mode found from `auto-mode-alist' or Fundamental mode
|
|
|
|
|
displays an image file as text. `image-minor-mode' provides the key
|
|
|
|
|
\\<image-mode-map>\\[image-toggle-display] to switch back to `image-mode'
|
|
|
|
|
to display an image file as the actual image.
|
|
|
|
|
|
|
|
|
|
You can use `image-mode-as-text' in `auto-mode-alist' when you want
|
|
|
|
|
to display an image file as text initially.
|
|
|
|
|
|
|
|
|
|
See commands `image-mode' and `image-minor-mode' for more information
|
|
|
|
|
on these modes."
|
|
|
|
|
(interactive)
|
|
|
|
|
(image-mode-to-text)
|
|
|
|
|
(message "%s" (concat
|
|
|
|
|
(substitute-command-keys
|
|
|
|
|
"Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as ")
|
|
|
|
|
(if (image-get-display-property)
|
|
|
|
|
"text" "an image or hex") ".")))
|
2009-12-04 21:43:07 +00:00
|
|
|
|
|
|
|
|
|
(define-obsolete-function-alias 'image-mode-maybe 'image-mode "23.2")
|
2005-03-25 19:57:21 +00:00
|
|
|
|
|
|
|
|
|
(defun image-toggle-display-text ()
|
2009-12-04 21:43:07 +00:00
|
|
|
|
"Show the image file as text.
|
|
|
|
|
Remove text properties that display the image."
|
|
|
|
|
(let ((inhibit-read-only t)
|
|
|
|
|
(buffer-undo-list t)
|
|
|
|
|
(modified (buffer-modified-p)))
|
|
|
|
|
(remove-list-of-text-properties (point-min) (point-max)
|
2011-09-19 19:27:30 +00:00
|
|
|
|
'(display read-nonsticky ;; intangible
|
2009-12-04 21:43:07 +00:00
|
|
|
|
read-only front-sticky))
|
|
|
|
|
(set-buffer-modified-p modified)
|
|
|
|
|
(if (called-interactively-p 'any)
|
|
|
|
|
(message "Repeat this command to go back to displaying the image"))))
|
2005-03-18 00:15:23 +00:00
|
|
|
|
|
2006-07-17 20:55:07 +00:00
|
|
|
|
(defvar archive-superior-buffer)
|
|
|
|
|
(defvar tar-superior-buffer)
|
2010-05-22 16:48:01 +00:00
|
|
|
|
(declare-function image-flush "image.c" (spec &optional frame))
|
2006-07-17 20:55:07 +00:00
|
|
|
|
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(defun image-toggle-display-image ()
|
|
|
|
|
"Show the image of the image file.
|
|
|
|
|
Turn the image data into a real image, but only if the whole file
|
|
|
|
|
was inserted."
|
2012-02-02 00:49:06 +00:00
|
|
|
|
(unless (derived-mode-p 'image-mode)
|
2011-04-09 20:28:01 +00:00
|
|
|
|
(error "The buffer is not in Image mode"))
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(let* ((filename (buffer-file-name))
|
|
|
|
|
(data-p (not (and filename
|
|
|
|
|
(file-readable-p filename)
|
|
|
|
|
(not (file-remote-p filename))
|
|
|
|
|
(not (buffer-modified-p))
|
|
|
|
|
(not (and (boundp 'archive-superior-buffer)
|
|
|
|
|
archive-superior-buffer))
|
|
|
|
|
(not (and (boundp 'tar-superior-buffer)
|
2015-11-17 02:27:51 +00:00
|
|
|
|
tar-superior-buffer))
|
|
|
|
|
;; This means the buffer holds the
|
|
|
|
|
;; decrypted content (bug#21870).
|
|
|
|
|
(not (and (boundp 'epa-file-encrypt-to)
|
|
|
|
|
(local-variable-p
|
|
|
|
|
'epa-file-encrypt-to))))))
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(file-or-data (if data-p
|
|
|
|
|
(string-make-unibyte
|
|
|
|
|
(buffer-substring-no-properties (point-min) (point-max)))
|
|
|
|
|
filename))
|
2014-09-18 18:34:59 +00:00
|
|
|
|
;; If we have a `fit-width' or a `fit-height', don't limit
|
|
|
|
|
;; the size of the image to the window size.
|
|
|
|
|
(edges (and (null image-transform-resize)
|
|
|
|
|
(window-inside-pixel-edges
|
|
|
|
|
(get-buffer-window (current-buffer)))))
|
2014-08-05 18:18:39 +00:00
|
|
|
|
(type (if (fboundp 'imagemagick-types)
|
|
|
|
|
'imagemagick
|
|
|
|
|
(image-type file-or-data nil data-p)))
|
2014-09-18 18:34:59 +00:00
|
|
|
|
(image (if (not edges)
|
|
|
|
|
(create-image file-or-data type data-p)
|
|
|
|
|
(create-image file-or-data type data-p
|
|
|
|
|
:max-width (- (nth 2 edges) (nth 0 edges))
|
|
|
|
|
:max-height (- (nth 3 edges) (nth 1 edges)))))
|
2011-05-29 21:35:35 +00:00
|
|
|
|
(inhibit-read-only t)
|
|
|
|
|
(buffer-undo-list t)
|
|
|
|
|
(modified (buffer-modified-p))
|
|
|
|
|
props)
|
|
|
|
|
|
2011-06-07 18:32:12 +00:00
|
|
|
|
;; Discard any stale image data before looking it up again.
|
|
|
|
|
(image-flush image)
|
2011-05-29 21:35:35 +00:00
|
|
|
|
(setq image (append image (image-transform-properties image)))
|
|
|
|
|
(setq props
|
2009-12-04 21:43:07 +00:00
|
|
|
|
`(display ,image
|
2011-09-19 19:27:30 +00:00
|
|
|
|
;; intangible ,image
|
|
|
|
|
rear-nonsticky (display) ;; intangible
|
2009-12-04 21:43:07 +00:00
|
|
|
|
read-only t front-sticky (read-only)))
|
2011-05-29 21:35:35 +00:00
|
|
|
|
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(let ((buffer-file-truename nil)) ; avoid changing dir mtime by lock_file
|
|
|
|
|
(add-text-properties (point-min) (point-max) props)
|
|
|
|
|
(restore-buffer-modified-p modified))
|
|
|
|
|
;; Inhibit the cursor when the buffer contains only an image,
|
|
|
|
|
;; because cursors look very strange on top of images.
|
|
|
|
|
(setq cursor-type nil)
|
|
|
|
|
;; This just makes the arrow displayed in the right fringe
|
|
|
|
|
;; area look correct when the image is wider than the window.
|
|
|
|
|
(setq truncate-lines t)
|
2011-02-18 17:59:06 +00:00
|
|
|
|
;; Disable adding a newline at the end of the image file when it
|
|
|
|
|
;; is written with, e.g., C-x C-w.
|
|
|
|
|
(if (coding-system-equal (coding-system-base buffer-file-coding-system)
|
|
|
|
|
'no-conversion)
|
2013-05-27 00:59:33 +00:00
|
|
|
|
(setq-local find-file-literally t))
|
|
|
|
|
;; Allow navigation of large images.
|
|
|
|
|
(setq-local auto-hscroll-mode nil)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(setq image-type type)
|
|
|
|
|
(if (eq major-mode 'image-mode)
|
|
|
|
|
(setq mode-name (format "Image[%s]" type)))
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(image-transform-check-size)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(if (called-interactively-p 'any)
|
|
|
|
|
(message "Repeat this command to go back to displaying the file as text"))))
|
|
|
|
|
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(defun image-toggle-hex-display ()
|
|
|
|
|
"Toggle between image and hex display."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if (image-get-display-property)
|
|
|
|
|
(image-mode-as-hex)
|
|
|
|
|
(if (eq major-mode 'fundamental-mode)
|
|
|
|
|
(image-mode-as-hex)
|
|
|
|
|
(image-mode))))
|
|
|
|
|
|
2005-03-18 00:15:23 +00:00
|
|
|
|
(defun image-toggle-display ()
|
2011-04-09 19:57:47 +00:00
|
|
|
|
"Toggle between image and text display.
|
2016-02-27 17:27:31 +00:00
|
|
|
|
|
2011-04-09 19:57:47 +00:00
|
|
|
|
If the current buffer is displaying an image file as an image,
|
2016-02-27 17:27:31 +00:00
|
|
|
|
call `image-mode-as-text' to switch to text or hex display.
|
|
|
|
|
Otherwise, display the image by calling `image-mode'"
|
2005-03-18 00:15:23 +00:00
|
|
|
|
(interactive)
|
2008-02-18 04:08:04 +00:00
|
|
|
|
(if (image-get-display-property)
|
2009-12-04 21:43:07 +00:00
|
|
|
|
(image-mode-as-text)
|
2016-02-27 17:27:31 +00:00
|
|
|
|
(if (eq major-mode 'hexl-mode)
|
|
|
|
|
(image-mode-as-text)
|
|
|
|
|
(image-mode))))
|
2010-05-25 16:03:53 +00:00
|
|
|
|
|
2015-02-04 20:02:14 +00:00
|
|
|
|
(defun image-kill-buffer ()
|
|
|
|
|
"Kill the current buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(kill-buffer (current-buffer)))
|
|
|
|
|
|
2010-05-25 16:03:53 +00:00
|
|
|
|
(defun image-after-revert-hook ()
|
2016-07-25 21:40:35 +00:00
|
|
|
|
;; Fixes bug#21598
|
|
|
|
|
(when (not (image-get-display-property))
|
|
|
|
|
(image-toggle-display-image))
|
2010-05-25 16:03:53 +00:00
|
|
|
|
(when (image-get-display-property)
|
|
|
|
|
(image-toggle-display-text)
|
|
|
|
|
;; Update image display.
|
2011-05-21 02:09:49 +00:00
|
|
|
|
(mapc (lambda (window) (redraw-frame (window-frame window)))
|
|
|
|
|
(get-buffer-window-list (current-buffer) 'nomini 'visible))
|
2010-05-25 16:03:53 +00:00
|
|
|
|
(image-toggle-display-image)))
|
|
|
|
|
|
2011-06-07 18:32:12 +00:00
|
|
|
|
|
|
|
|
|
;;; Animated images
|
|
|
|
|
|
|
|
|
|
(defcustom image-animate-loop nil
|
2012-02-03 08:44:30 +00:00
|
|
|
|
"Non-nil means animated images loop forever, rather than playing once."
|
2011-06-07 18:32:12 +00:00
|
|
|
|
:type 'boolean
|
|
|
|
|
:version "24.1"
|
|
|
|
|
:group 'image)
|
|
|
|
|
|
|
|
|
|
(defun image-toggle-animation ()
|
2012-02-03 08:44:30 +00:00
|
|
|
|
"Start or stop animating the current image.
|
|
|
|
|
If `image-animate-loop' is non-nil, animation loops forever.
|
|
|
|
|
Otherwise it plays once, then stops."
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((image (image-get-display-property))
|
|
|
|
|
animation)
|
|
|
|
|
(cond
|
|
|
|
|
((null image)
|
|
|
|
|
(error "No image is present"))
|
2013-02-16 19:56:50 +00:00
|
|
|
|
((null (setq animation (image-multi-frame-p image)))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(message "No image animation."))
|
|
|
|
|
(t
|
|
|
|
|
(let ((timer (image-animate-timer image)))
|
|
|
|
|
(if timer
|
|
|
|
|
(cancel-timer timer)
|
|
|
|
|
(let ((index (plist-get (cdr image) :index)))
|
|
|
|
|
;; If we're at the end, restart.
|
|
|
|
|
(and index
|
|
|
|
|
(>= index (1- (car animation)))
|
|
|
|
|
(setq index nil))
|
|
|
|
|
(image-animate image index
|
|
|
|
|
(if image-animate-loop t)))))))))
|
|
|
|
|
|
2013-08-16 06:33:08 +00:00
|
|
|
|
(defun image--set-speed (speed &optional multiply)
|
|
|
|
|
"Set speed of an animated image to SPEED.
|
|
|
|
|
If MULTIPLY is non-nil, treat SPEED as a multiplication factor.
|
|
|
|
|
If SPEED is `reset', reset the magnitude of the speed to 1."
|
|
|
|
|
(let ((image (image-get-display-property)))
|
|
|
|
|
(cond
|
|
|
|
|
((null image)
|
|
|
|
|
(error "No image is present"))
|
|
|
|
|
((null image-multi-frame)
|
|
|
|
|
(message "No image animation."))
|
|
|
|
|
(t
|
|
|
|
|
(if (eq speed 'reset)
|
|
|
|
|
(setq speed (if (< (image-animate-get-speed image) 0)
|
|
|
|
|
-1 1)
|
|
|
|
|
multiply nil))
|
|
|
|
|
(image-animate-set-speed image speed multiply)
|
|
|
|
|
;; FIXME Hack to refresh an active image.
|
|
|
|
|
(when (image-animate-timer image)
|
|
|
|
|
(image-toggle-animation)
|
|
|
|
|
(image-toggle-animation))
|
|
|
|
|
(message "Image speed is now %s" (image-animate-get-speed image))))))
|
|
|
|
|
|
|
|
|
|
(defun image-increase-speed ()
|
|
|
|
|
"Increase the speed of current animated image by a factor of 2."
|
|
|
|
|
(interactive)
|
|
|
|
|
(image--set-speed 2 t))
|
|
|
|
|
|
|
|
|
|
(defun image-decrease-speed ()
|
|
|
|
|
"Decrease the speed of current animated image by a factor of 2."
|
|
|
|
|
(interactive)
|
|
|
|
|
(image--set-speed 0.5 t))
|
|
|
|
|
|
|
|
|
|
(defun image-reverse-speed ()
|
|
|
|
|
"Reverse the animation of the current image."
|
|
|
|
|
(interactive)
|
|
|
|
|
(image--set-speed -1 t))
|
|
|
|
|
|
|
|
|
|
(defun image-reset-speed ()
|
|
|
|
|
"Reset the animation speed of the current image."
|
|
|
|
|
(interactive)
|
|
|
|
|
(image--set-speed 'reset))
|
|
|
|
|
|
2013-02-16 03:29:39 +00:00
|
|
|
|
(defun image-goto-frame (n &optional relative)
|
|
|
|
|
"Show frame N of a multi-frame image.
|
|
|
|
|
Optional argument OFFSET non-nil means interpret N as relative to the
|
|
|
|
|
current frame. Frames are indexed from 1."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (or current-prefix-arg
|
|
|
|
|
(read-number "Show frame number: "))))
|
2013-02-16 19:20:21 +00:00
|
|
|
|
(let ((image (image-get-display-property)))
|
2013-02-16 03:29:39 +00:00
|
|
|
|
(cond
|
|
|
|
|
((null image)
|
|
|
|
|
(error "No image is present"))
|
2013-02-20 07:57:33 +00:00
|
|
|
|
((null image-multi-frame)
|
2013-02-16 03:29:39 +00:00
|
|
|
|
(message "No image animation."))
|
|
|
|
|
(t
|
2013-02-20 07:57:33 +00:00
|
|
|
|
(image-show-frame image
|
|
|
|
|
(if relative
|
|
|
|
|
(+ n (image-current-frame image))
|
|
|
|
|
(1- n)))))))
|
2013-02-16 03:29:39 +00:00
|
|
|
|
|
|
|
|
|
(defun image-next-frame (&optional n)
|
|
|
|
|
"Switch to the next frame of a multi-frame image.
|
|
|
|
|
With optional argument N, switch to the Nth frame after the current one.
|
|
|
|
|
If N is negative, switch to the Nth frame before the current one."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(image-goto-frame n t))
|
|
|
|
|
|
|
|
|
|
(defun image-previous-frame (&optional n)
|
|
|
|
|
"Switch to the previous frame of a multi-frame image.
|
|
|
|
|
With optional argument N, switch to the Nth frame before the current one.
|
|
|
|
|
If N is negative, switch to the Nth frame after the current one."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(image-next-frame (- n)))
|
|
|
|
|
|
2013-01-19 15:22:38 +00:00
|
|
|
|
|
|
|
|
|
;;; Switching to the next/previous image
|
|
|
|
|
|
|
|
|
|
(defun image-next-file (&optional n)
|
|
|
|
|
"Visit the next image in the same directory as the current image file.
|
|
|
|
|
With optional argument N, visit the Nth image file after the
|
|
|
|
|
current one, in cyclic alphabetical order.
|
|
|
|
|
|
|
|
|
|
This command visits the specified file via `find-alternate-file',
|
|
|
|
|
replacing the current Image mode buffer."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(unless (derived-mode-p 'image-mode)
|
|
|
|
|
(error "The buffer is not in Image mode"))
|
|
|
|
|
(unless buffer-file-name
|
|
|
|
|
(error "The current image is not associated with a file"))
|
|
|
|
|
(let* ((file (file-name-nondirectory buffer-file-name))
|
|
|
|
|
(images (image-mode--images-in-directory file))
|
|
|
|
|
(idx 0))
|
|
|
|
|
(catch 'image-visit-next-file
|
|
|
|
|
(dolist (f images)
|
|
|
|
|
(if (string= f file)
|
|
|
|
|
(throw 'image-visit-next-file (1+ idx)))
|
|
|
|
|
(setq idx (1+ idx))))
|
|
|
|
|
(setq idx (mod (+ idx (or n 1)) (length images)))
|
|
|
|
|
(find-alternate-file (nth idx images))))
|
|
|
|
|
|
|
|
|
|
(defun image-previous-file (&optional n)
|
|
|
|
|
"Visit the preceding image in the same directory as the current file.
|
|
|
|
|
With optional argument N, visit the Nth image file preceding the
|
|
|
|
|
current one, in cyclic alphabetical order.
|
|
|
|
|
|
|
|
|
|
This command visits the specified file via `find-alternate-file',
|
|
|
|
|
replacing the current Image mode buffer."
|
|
|
|
|
(interactive "p")
|
|
|
|
|
(image-next-file (- n)))
|
|
|
|
|
|
|
|
|
|
(defun image-mode--images-in-directory (file)
|
|
|
|
|
(let* ((dir (file-name-directory buffer-file-name))
|
|
|
|
|
(files (directory-files dir nil
|
|
|
|
|
(image-file-name-regexp) t)))
|
|
|
|
|
;; Add the current file to the list of images if necessary, in
|
|
|
|
|
;; case it does not match `image-file-name-regexp'.
|
|
|
|
|
(unless (member file files)
|
|
|
|
|
(push file files))
|
|
|
|
|
(sort files 'string-lessp)))
|
|
|
|
|
|
2009-02-05 23:59:52 +00:00
|
|
|
|
|
2007-12-26 11:48:37 +00:00
|
|
|
|
;;; Support for bookmark.el
|
2010-07-14 15:57:54 +00:00
|
|
|
|
(declare-function bookmark-make-record-default
|
|
|
|
|
"bookmark" (&optional no-file no-context posn))
|
2008-06-25 16:51:33 +00:00
|
|
|
|
(declare-function bookmark-prop-get "bookmark" (bookmark prop))
|
|
|
|
|
(declare-function bookmark-default-handler "bookmark" (bmk))
|
2007-12-26 11:48:37 +00:00
|
|
|
|
|
2008-06-25 16:51:33 +00:00
|
|
|
|
(defun image-bookmark-make-record ()
|
2010-07-17 21:35:19 +00:00
|
|
|
|
`(,@(bookmark-make-record-default nil 'no-context 0)
|
|
|
|
|
(image-type . ,image-type)
|
|
|
|
|
(handler . image-bookmark-jump)))
|
2007-12-26 11:48:37 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun image-bookmark-jump (bmk)
|
2008-01-02 07:49:04 +00:00
|
|
|
|
;; This implements the `handler' function interface for record type
|
2008-03-07 05:44:37 +00:00
|
|
|
|
;; returned by `bookmark-make-record-function', which see.
|
2008-06-25 16:51:33 +00:00
|
|
|
|
(prog1 (bookmark-default-handler bmk)
|
|
|
|
|
(when (not (string= image-type (bookmark-prop-get bmk 'image-type)))
|
|
|
|
|
(image-toggle-display))))
|
2009-02-05 23:59:52 +00:00
|
|
|
|
|
2010-06-26 21:17:02 +00:00
|
|
|
|
|
2012-02-08 03:45:27 +00:00
|
|
|
|
;; Not yet implemented.
|
2012-05-14 05:15:59 +00:00
|
|
|
|
;; (defvar image-transform-minor-mode-map
|
|
|
|
|
;; (let ((map (make-sparse-keymap)))
|
|
|
|
|
;; ;; (define-key map [(control ?+)] 'image-scale-in)
|
|
|
|
|
;; ;; (define-key map [(control ?-)] 'image-scale-out)
|
|
|
|
|
;; ;; (define-key map [(control ?=)] 'image-scale-none)
|
|
|
|
|
;; ;; (define-key map "c f h" 'image-scale-fit-height)
|
|
|
|
|
;; ;; (define-key map "c ]" 'image-rotate-right)
|
|
|
|
|
;; map)
|
|
|
|
|
;; "Minor mode keymap `image-transform-mode'.")
|
|
|
|
|
;;
|
|
|
|
|
;; (define-minor-mode image-transform-mode
|
|
|
|
|
;; "Minor mode for scaling and rotating images.
|
|
|
|
|
;; With a prefix argument ARG, enable the mode if ARG is positive,
|
|
|
|
|
;; and disable it otherwise. If called from Lisp, enable the mode
|
|
|
|
|
;; if ARG is omitted or nil. This minor mode requires Emacs to have
|
|
|
|
|
;; been compiled with ImageMagick support."
|
|
|
|
|
;; nil "image-transform" image-transform-minor-mode-map)
|
2012-02-08 03:45:27 +00:00
|
|
|
|
|
|
|
|
|
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(defsubst image-transform-width (width height)
|
|
|
|
|
"Return the bounding box width of a rotated WIDTH x HEIGHT rectangle.
|
|
|
|
|
The rotation angle is the value of `image-transform-rotation' in degrees."
|
|
|
|
|
(let ((angle (degrees-to-radians image-transform-rotation)))
|
|
|
|
|
;; Assume, w.l.o.g., that the vertices of the rectangle have the
|
|
|
|
|
;; coordinates (+-w/2, +-h/2) and that (0, 0) is the center of the
|
|
|
|
|
;; rotation by the angle A. The projections onto the first axis
|
|
|
|
|
;; of the vertices of the rotated rectangle are +- (w/2) cos A +-
|
|
|
|
|
;; (h/2) sin A, and the difference between the largest and the
|
|
|
|
|
;; smallest of the four values is the expression below.
|
|
|
|
|
(+ (* width (abs (cos angle))) (* height (abs (sin angle))))))
|
|
|
|
|
|
|
|
|
|
;; The following comment and code snippet are from
|
|
|
|
|
;; ImageMagick-6.7.4-4/magick/distort.c
|
|
|
|
|
|
2012-05-29 06:16:49 +00:00
|
|
|
|
;; /* Set the output image geometry to calculated 'best fit'.
|
2012-05-14 05:19:46 +00:00
|
|
|
|
;; Yes this tends to 'over do' the file image size, ON PURPOSE!
|
|
|
|
|
;; Do not do this for DePolar which needs to be exact for virtual tiling.
|
|
|
|
|
;; */
|
|
|
|
|
;; if ( fix_bounds ) {
|
|
|
|
|
;; geometry.x = (ssize_t) floor(min.x-0.5);
|
|
|
|
|
;; geometry.y = (ssize_t) floor(min.y-0.5);
|
|
|
|
|
;; geometry.width=(size_t) ceil(max.x-geometry.x+0.5);
|
|
|
|
|
;; geometry.height=(size_t) ceil(max.y-geometry.y+0.5);
|
|
|
|
|
;; }
|
|
|
|
|
|
|
|
|
|
;; Other parts of the same file show that here the origin is in the
|
|
|
|
|
;; left lower corner of the image rectangle, the center of the
|
|
|
|
|
;; rotation is the center of the rectangle and min.x and max.x
|
|
|
|
|
;; (resp. min.y and max.y) are the smallest and the largest of the
|
|
|
|
|
;; projections of the vertices onto the first (resp. second) axis.
|
|
|
|
|
|
|
|
|
|
(defun image-transform-fit-width (width height length)
|
|
|
|
|
"Return (w . h) so that a rotated w x h image has exactly width LENGTH.
|
|
|
|
|
The rotation angle is the value of `image-transform-rotation'.
|
|
|
|
|
Write W for WIDTH and H for HEIGHT. Then the w x h rectangle is
|
|
|
|
|
an \"approximately uniformly\" scaled W x H rectangle, which
|
|
|
|
|
currently means that w is one of floor(s W) + {0, 1, -1} and h is
|
|
|
|
|
floor(s H), where s can be recovered as the value of `image-transform-scale'.
|
|
|
|
|
The value of `image-transform-rotation' may be replaced by
|
|
|
|
|
a slightly different angle. Currently this is done for values
|
|
|
|
|
close to a multiple of 90, see `image-transform-right-angle-fudge'."
|
|
|
|
|
(cond ((< (abs (- (mod (+ image-transform-rotation 90) 180) 90))
|
|
|
|
|
image-transform-right-angle-fudge)
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(cl-assert (not (zerop width)) t)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(setq image-transform-rotation
|
|
|
|
|
(float (round image-transform-rotation))
|
|
|
|
|
image-transform-scale (/ (float length) width))
|
|
|
|
|
(cons length nil))
|
|
|
|
|
((< (abs (- (mod (+ image-transform-rotation 45) 90) 45))
|
|
|
|
|
image-transform-right-angle-fudge)
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(cl-assert (not (zerop height)) t)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(setq image-transform-rotation
|
|
|
|
|
(float (round image-transform-rotation))
|
|
|
|
|
image-transform-scale (/ (float length) height))
|
|
|
|
|
(cons nil length))
|
|
|
|
|
(t
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(cl-assert (not (and (zerop width) (zerop height))) t)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(setq image-transform-scale
|
|
|
|
|
(/ (float (1- length)) (image-transform-width width height)))
|
|
|
|
|
;; Assume we have a w x h image and an angle A, and let l =
|
|
|
|
|
;; l(w, h) = w |cos A| + h |sin A|, which is the actual width
|
|
|
|
|
;; of the bounding box of the rotated image, as calculated by
|
|
|
|
|
;; `image-transform-width'. The code snippet quoted above
|
|
|
|
|
;; means that ImageMagick puts the rotated image in
|
|
|
|
|
;; a bounding box of width L = 2 ceil((w+l+1)/2) - w.
|
|
|
|
|
;; Elementary considerations show that this is equivalent to
|
|
|
|
|
;; L - w being even and L-3 < l(w, h) <= L-1. In our case, L is
|
|
|
|
|
;; the given `length' parameter and our job is to determine
|
|
|
|
|
;; reasonable values for w and h which satisfy these
|
|
|
|
|
;; conditions.
|
|
|
|
|
(let ((w (floor (* image-transform-scale width)))
|
|
|
|
|
(h (floor (* image-transform-scale height))))
|
|
|
|
|
;; Let w and h as bound above. Then l(w, h) <= l(s W, s H)
|
|
|
|
|
;; = L-1 < l(w+1, h+1) = l(w, h) + l(1, 1) <= l(w, h) + 2,
|
|
|
|
|
;; hence l(w, h) > (L-1) - 2 = L-3.
|
|
|
|
|
(cons
|
|
|
|
|
(cond ((= (mod w 2) (mod length 2))
|
|
|
|
|
w)
|
|
|
|
|
;; l(w+1, h) >= l(w, h) > L-3, but does l(w+1, h) <=
|
|
|
|
|
;; L-1 hold?
|
|
|
|
|
((<= (image-transform-width (1+ w) h) (1- length))
|
|
|
|
|
(1+ w))
|
|
|
|
|
;; No, it doesn't, but this implies that l(w-1, h) =
|
|
|
|
|
;; l(w+1, h) - l(2, 0) >= l(w+1, h) - 2 > (L-1) -
|
|
|
|
|
;; 2 = L-3. Clearly, l(w-1, h) <= l(w, h) <= L-1.
|
|
|
|
|
(t
|
|
|
|
|
(1- w)))
|
|
|
|
|
h)))))
|
|
|
|
|
|
|
|
|
|
(defun image-transform-check-size ()
|
2012-11-23 17:41:01 +00:00
|
|
|
|
"Check that the image exactly fits the width/height of the window.
|
|
|
|
|
|
|
|
|
|
Do this for an image of type `imagemagick' to make sure that the
|
|
|
|
|
elisp code matches the way ImageMagick computes the bounding box
|
|
|
|
|
of a rotated image."
|
|
|
|
|
(when (and (not (numberp image-transform-resize))
|
|
|
|
|
(boundp 'image-type)
|
|
|
|
|
(eq image-type 'imagemagick))
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(let ((size (image-display-size (image-get-display-property) t)))
|
|
|
|
|
(cond ((eq image-transform-resize 'fit-width)
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(cl-assert (= (car size)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(- (nth 2 (window-inside-pixel-edges))
|
|
|
|
|
(nth 0 (window-inside-pixel-edges))))
|
|
|
|
|
t))
|
|
|
|
|
((eq image-transform-resize 'fit-height)
|
Reduce use of (require 'cl).
* admin/bzrmerge.el: Use cl-lib.
* leim/quail/hangul.el: Don't require CL.
* leim/quail/ipa.el: Use cl-lib.
* vc/smerge-mode.el, vc/pcvs.el, vc/pcvs-util.el, vc/pcvs-info.el:
* vc/diff-mode.el, vc/cvs-status.el, uniquify.el, scroll-bar.el:
* register.el, progmodes/sh-script.el, net/gnutls.el, net/dbus.el:
* msb.el, mpc.el, minibuffer.el, international/ucs-normalize.el:
* international/quail.el, info-xref.el, imenu.el, image-mode.el:
* font-lock.el, filesets.el, edmacro.el, doc-view.el, bookmark.el:
* battery.el, avoid.el, abbrev.el: Use cl-lib.
* vc/pcvs-parse.el, vc/pcvs-defs.el, vc/log-view.el, vc/log-edit.el:
* vc/diff.el, simple.el, pcomplete.el, lpr.el, comint.el, loadhist.el:
* jit-lock.el, international/iso-ascii.el, info.el, frame.el, bs.el:
* emulation/crisp.el, electric.el, dired.el, cus-dep.el, composite.el:
* calculator.el, autorevert.el, apropos.el: Don't require CL.
* emacs-bytecomp.el (byte-recompile-directory, display-call-tree)
(byte-compile-unfold-bcf, byte-compile-check-variable):
* emacs-byte-opt.el (byte-compile-trueconstp)
(byte-compile-nilconstp):
* emacs-autoload.el (make-autoload): Use pcase.
* face-remap.el (text-scale-adjust): Simplify pcase patterns.
2012-07-10 11:51:54 +00:00
|
|
|
|
(cl-assert (= (cdr size)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(- (nth 3 (window-inside-pixel-edges))
|
|
|
|
|
(nth 1 (window-inside-pixel-edges))))
|
|
|
|
|
t))))))
|
|
|
|
|
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(defun image-transform-properties (spec)
|
|
|
|
|
"Return rescaling/rotation properties for image SPEC.
|
|
|
|
|
These properties are determined by the Image mode variables
|
|
|
|
|
`image-transform-resize' and `image-transform-rotation'. The
|
|
|
|
|
return value is suitable for appending to an image spec.
|
2011-05-29 21:35:35 +00:00
|
|
|
|
|
2011-11-14 06:27:12 +00:00
|
|
|
|
Rescaling and rotation properties only take effect if Emacs is
|
2011-05-29 21:35:35 +00:00
|
|
|
|
compiled with ImageMagick support."
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(setq image-transform-scale 1.0)
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(when (or image-transform-resize
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(/= image-transform-rotation 0.0))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
;; Note: `image-size' looks up and thus caches the untransformed
|
|
|
|
|
;; image. There's no easy way to prevent that.
|
|
|
|
|
(let* ((size (image-size spec t))
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(resized
|
2011-06-07 18:32:12 +00:00
|
|
|
|
(cond
|
|
|
|
|
((numberp image-transform-resize)
|
2012-05-14 05:15:59 +00:00
|
|
|
|
(unless (= image-transform-resize 1)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(setq image-transform-scale image-transform-resize)
|
|
|
|
|
(cons nil (floor (* image-transform-resize (cdr size))))))
|
|
|
|
|
((eq image-transform-resize 'fit-width)
|
|
|
|
|
(image-transform-fit-width
|
|
|
|
|
(car size) (cdr size)
|
|
|
|
|
(- (nth 2 (window-inside-pixel-edges))
|
|
|
|
|
(nth 0 (window-inside-pixel-edges)))))
|
2011-06-07 18:32:12 +00:00
|
|
|
|
((eq image-transform-resize 'fit-height)
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(let ((res (image-transform-fit-width
|
|
|
|
|
(cdr size) (car size)
|
|
|
|
|
(- (nth 3 (window-inside-pixel-edges))
|
|
|
|
|
(nth 1 (window-inside-pixel-edges))))))
|
|
|
|
|
(cons (cdr res) (car res)))))))
|
|
|
|
|
`(,@(when (car resized)
|
|
|
|
|
(list :width (car resized)))
|
|
|
|
|
,@(when (cdr resized)
|
|
|
|
|
(list :height (cdr resized)))
|
|
|
|
|
,@(unless (= 0.0 image-transform-rotation)
|
|
|
|
|
(list :rotation image-transform-rotation))))))
|
2010-06-26 21:17:02 +00:00
|
|
|
|
|
|
|
|
|
(defun image-transform-set-scale (scale)
|
2011-04-09 20:28:01 +00:00
|
|
|
|
"Prompt for a number, and resize the current image by that amount.
|
|
|
|
|
This command has no effect unless Emacs is compiled with
|
|
|
|
|
ImageMagick support."
|
|
|
|
|
(interactive "nScale: ")
|
2011-04-13 02:16:42 +00:00
|
|
|
|
(setq image-transform-resize scale)
|
2011-04-09 20:28:01 +00:00
|
|
|
|
(image-toggle-display-image))
|
2010-06-26 21:17:02 +00:00
|
|
|
|
|
|
|
|
|
(defun image-transform-fit-to-height ()
|
2011-04-09 20:28:01 +00:00
|
|
|
|
"Fit the current image to the height of the current window.
|
|
|
|
|
This command has no effect unless Emacs is compiled with
|
|
|
|
|
ImageMagick support."
|
2010-06-26 21:17:02 +00:00
|
|
|
|
(interactive)
|
2011-04-09 20:28:01 +00:00
|
|
|
|
(setq image-transform-resize 'fit-height)
|
|
|
|
|
(image-toggle-display-image))
|
2010-06-26 21:17:02 +00:00
|
|
|
|
|
2010-06-27 00:18:55 +00:00
|
|
|
|
(defun image-transform-fit-to-width ()
|
2011-04-09 20:28:01 +00:00
|
|
|
|
"Fit the current image to the width of the current window.
|
|
|
|
|
This command has no effect unless Emacs is compiled with
|
|
|
|
|
ImageMagick support."
|
2010-06-27 00:18:55 +00:00
|
|
|
|
(interactive)
|
2011-04-09 20:28:01 +00:00
|
|
|
|
(setq image-transform-resize 'fit-width)
|
|
|
|
|
(image-toggle-display-image))
|
2010-06-26 21:17:02 +00:00
|
|
|
|
|
|
|
|
|
(defun image-transform-set-rotation (rotation)
|
2011-04-09 20:28:01 +00:00
|
|
|
|
"Prompt for an angle ROTATION, and rotate the image by that amount.
|
|
|
|
|
ROTATION should be in degrees. This command has no effect unless
|
|
|
|
|
Emacs is compiled with ImageMagick support."
|
|
|
|
|
(interactive "nRotation angle (in degrees): ")
|
2012-05-14 05:19:46 +00:00
|
|
|
|
(setq image-transform-rotation (float (mod rotation 360)))
|
2011-04-09 20:28:01 +00:00
|
|
|
|
(image-toggle-display-image))
|
2010-06-26 21:17:02 +00:00
|
|
|
|
|
2014-08-12 14:16:45 +00:00
|
|
|
|
(defun image-transform-reset ()
|
|
|
|
|
"Display the current image with the default size and rotation.
|
|
|
|
|
This command has no effect unless Emacs is compiled with
|
|
|
|
|
ImageMagick support."
|
|
|
|
|
(interactive)
|
|
|
|
|
(setq image-transform-resize nil
|
|
|
|
|
image-transform-rotation 0.0
|
|
|
|
|
image-transform-scale 1)
|
|
|
|
|
(image-toggle-display-image))
|
|
|
|
|
|
2005-03-18 00:15:23 +00:00
|
|
|
|
(provide 'image-mode)
|
|
|
|
|
|
|
|
|
|
;;; image-mode.el ends here
|