From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexander Kuleshov Newsgroups: gmane.emacs.bugs Subject: bug#22453: [PATCH] Support for switching to hexl-mode from image mode Date: Sat, 27 Feb 2016 21:15:44 +0600 Message-ID: References: <1453617036-17528-1-git-send-email-kuleshovmail@gmail.com> <83fuxn3ufa.fsf@gnu.org> <20160124145941.GA1301@localhost> <831t973qs3.fsf@gnu.org> <20160124185755.GB6434@localhost> <83r3h63egs.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1456586242 16274 80.91.229.3 (27 Feb 2016 15:17:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 27 Feb 2016 15:17:22 +0000 (UTC) Cc: 22453@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Feb 27 16:17:13 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aZgcL-0007un-4h for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Feb 2016 16:17:13 +0100 Original-Received: from localhost ([::1]:55155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZgcJ-0000s4-RU for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Feb 2016 10:17:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZgcF-0000ri-77 for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2016 10:17:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZgcA-0002W3-6V for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2016 10:17:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZgcA-0002Vy-3C for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2016 10:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aZgc9-0006me-Sg for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2016 10:17:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alexander Kuleshov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Feb 2016 15:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22453 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 22453-submit@debbugs.gnu.org id=B22453.145658617226007 (code B ref 22453); Sat, 27 Feb 2016 15:17:01 +0000 Original-Received: (at 22453) by debbugs.gnu.org; 27 Feb 2016 15:16:12 +0000 Original-Received: from localhost ([127.0.0.1]:49004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aZgbL-0006lP-IP for submit@debbugs.gnu.org; Sat, 27 Feb 2016 10:16:11 -0500 Original-Received: from mail-wm0-f43.google.com ([74.125.82.43]:36428) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aZgbJ-0006lC-Qq for 22453@debbugs.gnu.org; Sat, 27 Feb 2016 10:16:10 -0500 Original-Received: by mail-wm0-f43.google.com with SMTP id g62so107649443wme.1 for <22453@debbugs.gnu.org>; Sat, 27 Feb 2016 07:16:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=BHlWgEBUWXC0/JiKgbkdsHM+6y3slxrn5ZDFItYg+Ac=; b=n7a8k60TmPkInU/wupmCBnUQUDzr+v/WPvS3zE1blYotRnjYvIiNr+Z3HrhirywLjX JcOf/y+Z6TipuOvkfR2Hv/EH8yF9+aN8n0/vL1WSiL55BQaOLi1fR6TIP4A9QRjbnmur jAEu+KiusU8P7bCtV/ZKoALv6x09n0k7bnykzgx3vwpUwODMMAMGFxIjDNi1lDjT17pZ nXhKi2m7gxR/V+nW+8B8d8GB3ZN4qzdDCYRLXhD/O/4JNmQ+cFyNCrv5LNXl7k7rVVWT /k0gaW85+Nj3jSLNa0S+HAbmvPijpyoHrh6V/3QHLm+IcsUpfiAP5YDzDqIiKGGe1OpA IHNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=BHlWgEBUWXC0/JiKgbkdsHM+6y3slxrn5ZDFItYg+Ac=; b=g6nSpkLfc07afV/ait6+n/7+hylyIiJU5jvQ5BTfd34MV4WjpD/c5XQxxcX+izTs0X KsXUnBDT1SvUUzVCvI0Ko6Bn7nkpdQUTuxFsvBpI7Ddg4Z9Rull1CwjuwnJHgC9o49oH j6uIxDY58mua6wR5LL/d+wb24jWfYf5DBAyV8y9RCcEd5owK3CfC+uzGDYZe0oliQ2Pd 4rve2JLn6QzoDGI75+ICy+DiH4K04Mjr76qQpxw/pbFDCXiGS8b3lyulwgamU5zQwOmt tAH/8d5wC//zbVJW2422VFnLv2pifBkL0G3+HYlynRCnjL6dViGFPjyqAECmB0v23ghR j7jQ== X-Gm-Message-State: AD7BkJI4tPlR/t9ipuTu2juIBE71gaei8suOdx9UX4oB2PqN0FB9sEweXIMEie5HWMyFAQR9bKzc4UdOybgniQ== X-Received: by 10.28.145.9 with SMTP id t9mr3405814wmd.54.1456586164006; Sat, 27 Feb 2016 07:16:04 -0800 (PST) Original-Received: by 10.27.7.141 with HTTP; Sat, 27 Feb 2016 07:15:44 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:113956 Archived-At: Add support for switching to hexl-mode from image mode * doc/emacs/files.texi: Document image-toggle-hex-display * lisp/image-mode.el (image-toggle-hex-display, image-mode-to-text): New functions --- doc/emacs/files.texi | 3 ++ lisp/image-mode.el | 98 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 72 insertions(+), 29 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index ab20d4a..bbb6070 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1969,6 +1969,9 @@ File Conveniences major mode, you can type @kbd{C-c C-c} (@code{image-toggle-display}) to toggle between displaying the file as an image in the Emacs buffer, and displaying its underlying text (or raw byte) representation. +Additionally you can type @kbd{C-c C-x} (@code{image-toggle-hex-display}) +to toggle between displaying the file as an image in the Emacs buffer, +and displaying it in hex representation. Displaying the file as an image works only if Emacs is compiled with support for displaying such images. If the displayed image is wider or taller than the frame, the usual point motion keys (@kbd{C-f}, diff --git a/lisp/image-mode.el b/lisp/image-mode.el index e2037b9..2d560d3 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -24,8 +24,8 @@ ;;; Commentary: ;; Defines a major mode for visiting image files -;; that allows conversion between viewing the text of the file -;; and viewing the file as an image. Viewing the image +;; that allows conversion between viewing the text of the file, +;; hex of the file and viewing the file as an image. Viewing the image ;; 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 @@ -375,6 +375,7 @@ image-mode-map (set-keymap-parent map special-mode-map) (set-keymap-parent map image-map) (define-key map "\C-c\C-c" 'image-toggle-display) + (define-key map "\C-c\C-x" 'image-toggle-hex-display) (define-key map (kbd "SPC") 'image-scroll-up) (define-key map (kbd "S-SPC") 'image-scroll-down) (define-key map (kbd "DEL") 'image-scroll-down) @@ -407,6 +408,8 @@ image-mode-map '("Image" ["Show as Text" image-toggle-display :active t :help "Show image as text"] + ["Show as Hex" image-toggle-hex-display :active t + :help "Show image as hex"] "--" ["Fit to Window Height" image-transform-fit-to-height :visible (eq image-type 'imagemagick) @@ -481,6 +484,7 @@ image-mode-map (defvar image-minor-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-c\C-c" 'image-toggle-display) + (define-key map "\C-c\C-x" 'image-toggle-hex-display) map) "Mode keymap for `image-minor-mode'.") @@ -491,8 +495,8 @@ bookmark-make-record-function ;;;###autoload (defun image-mode () "Major mode for image files. -You can use \\\\[image-toggle-display] -to toggle between display as an image and display as text. +You can use \\\\[image-toggle-display] or \\\\[image-toggle-hex-display] +to toggle between display as an image and display as text or hex. Key bindings: \\{image-mode-map}" @@ -531,7 +535,7 @@ image-mode (run-mode-hooks 'image-mode-hook) (let ((image (image-get-display-property)) (msg1 (substitute-command-keys - "Type \\[image-toggle-display] to view the image as ")) + "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as ")) animated) (cond ((null image) @@ -560,7 +564,7 @@ image-mode ;;; (substitute-command-keys ;;; "\\[image-toggle-animation] to animate.")))) (t - (message "%s" (concat msg1 "text.")))))) + (message "%s" (concat msg1 "text or hex.")))))) (error (image-mode-as-text) @@ -586,19 +590,10 @@ image-minor-mode (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t))) ;;;###autoload -(defun image-mode-as-text () +(defun image-mode-to-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-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) +A non-mage major mode found from `auto-mode-alist' or fundamental mode +displays an image file as text." ;; image-mode-as-text = normal-mode + image-minor-mode (let ((previous-image-type image-type)) ; preserve `image-type' (if image-mode-previous-major-mode @@ -626,12 +621,49 @@ image-mode-as-text ;; Enable image minor mode with `C-c C-c'. (image-minor-mode 1) ;; Show the image file as text. - (image-toggle-display-text) - (message "%s" (concat - (substitute-command-keys - "Type \\[image-toggle-display] to view the image as ") - (if (image-get-display-property) - "text" "an image") ".")))) + (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-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-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") "."))) (define-obsolete-function-alias 'image-mode-maybe 'image-mode "23.2") @@ -726,16 +758,23 @@ image-toggle-display-image (if (called-interactively-p 'any) (message "Repeat this command to go back to displaying the file as text")))) +(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)))) + (defun image-toggle-display () - "Toggle between image and text display. -If the current buffer is displaying an image file as an image, -call `image-mode-as-text' to switch to text. Otherwise, display -the image by calling `image-mode'." + "Toggle between image and text display." (interactive) (if (image-get-display-property) (image-mode-as-text) - (image-mode))) + (if (eq major-mode 'hexl-mode) + (image-mode-as-text) + (image-mode)))) (defun image-kill-buffer () "Kill the current buffer." -- 2.7.2.335.g3476f70