annotate lisp/image-file.el @ 83004:7900111db01c

Converted display hooks to be display-local. Plus many bugfixes. lib-src/emacsclient.c (window_change_signal): Renamed to pass_signal_to_emacs. (init_signal): Pass SIGINT and SIGQUIT to the emacs process. lisp/faces.el (face-valid-attribute-values): Use the window-system function, not the variable. (read-face-attribute, face-spec-set-match-display, frame-set-background-mode) (face-set-after-frame-default): Ditto. lisp/frame.el (make-frame-on-tty): Added interactive declaration (suggested by Robert J. Chassell). Use tty-create-frame-with-faces, not make-terminal-frame. src/termhooks.h (struct display_method): Renamed to display for brevity. (struct display): Added all display hook variables as members of this structure. Added next_display, reference_count, type and display_info components. (FRAME_MUST_WRITE_SPACES, FRAME_FAST_CLEAR_END_OF_LINE, FRAME_LINE_INS_DEL_OK) (FRAME_CHAR_INS_DEL_OK, FRAME_SCROLL_REGION_OK, FRAME_SCROLL_REGION_COST) (FRAME_MEMORY_BELOW_FRAME, FRAME_RIF): Updated for struct display. (FRAME_DISPLAY): New macro. (create_display, delete_display): New prototypes. src/frame.h (struct frame): Added `display' member, removed display_method. (FRAME_LIVE_P): Look at f->display, not f->output_data. src/termchar.h (struct tty_display_info): Removed display_method component. (FRAME_TTY): Use the display structure, not output_data. src/term.c (display_list): New variable. (cursor_to_hook, raw_cursor_to_hook, clear_to_end_hook, clear_frame_hook) (clear_end_of_line_hook, ins_del_lines_hook, delete_glyphs_hook) (ring_bell_hook, reset_terminal_modes_hook, set_terminal_modes_hook) (update_begin_hook, update_end_hook, set_terminal_window_hook) (insert_glyphs_hook, write_glyphs_hook, delete_glyphs_hoo, read_socket_hook) (frame_up_to_date_hook, mouse_position_hook, frame_rehighlight_hook) (frame_raise_lower_hook, set_vertical_scroll_bar_hook, condemn_scroll_bars_hook) (redeem_scroll_bar_hook, judge_scroll_bars_hook): Moved to struct display. (tty_display_method_template): Removed. (syms_of_term): Don't initialize tty_display_method_template. (ring_bell, set_terminal_modes, reset_terminal_modes, update_begin) (update_end, set_terminal_window, cursor_to, raw_cursor_to, clear_to_end) (clear_frame, clear_end_of_line, write_glyphs, insert_glyphs) (delete_glyphs, ins_del_lines): Access display hooks through the frame pointer. (Ftty_display_color_p): Use the frame given as a parameter, or else return nil. (Ftty_display_color_cells): Ditto. (get_named_tty): Renamed to get_named_tty_display, changed return type to struct display. (term_dummy_init): Renamed to initial_term_init. Create and return an initial display. (term_init): Initialize a new struct display and return a pointer to it instead of tty_display_info. Removed frame initialization kludge. (Fdelete_tty): Updated for struct display. (delete_tty): The parameter type is now struct display, not tty_display_info. Delete the display, too. (create_tty_output): New function for creating tty_output structures. (delete_tty_output): New function for deleting tty_output structures. (create_display): New function for creating and registering display structures. (delete_display): New function for deleting and unregistering display structures. src/dispextern.h: Updated prototypes. src/dispnew.c: Include frame.h before termhooks.h. (init_display): Updated term_init call to new signature. src/emacs.c: Include frame.h (for termhooks.h). src/keymap.c: Ditto. src/lread.c: Ditto. src/xsmfns.c: Ditto. src/process.c: Include frame.h before termhooks.h. src/frame.c (Fwindow_system): New function. (syms_of_frame): Initialize it. (make_terminal_frame): Open the terminal device before creating the new frame. Disable scrollbars here, term_init cannot do that anymore. (Fdelete_frame): Use the new delete_frame_hook, don't do display-specific frame deletion here. Ditto for delete_display_hook. (Fmouse_position, Fmouse_pixel_position, Fraise_frame, Flower_frame) (Fredirect_frame_focus): Access display hooks through the frame pointer. src/keyboard.c: Include frame.h before termhooks.h. (start_polling, input_polling_used, stop_polling, gobble_input): Ignore read_socket_hook. (kbd_buffer_get_event, Fset_input_mode): Access display hooks through the frame pointer. (read_avail_input): Loop through all display devices for and call all read_socket_hook functions. Check ttys even if read_socket_hook returned an error. src/sysdep.c (discard_tty_input): Ignore read_socket_hook. (stuff_char): Don't do anything if the current frame is not on a termcap display. (request_sigio, unrequest_sigio): Ignore read_socket_hook. (init_sys_modes): Always call narrow_foreground_group. Set up terminal modes and sigio even under X. src/xdisp.c (message2_nolog, message3_nolog, redisplay_internal) (set_vertical_scroll_bar, redisplay_window): Access display hooks through the frame pointer. (echo_area_display): Don't be afraid of termcap frames during an X+tty combo session. src/xfaces.c: Include termhooks.h. (Ftty_supports_face_attributes_p): Use the given frame, not selected_frame. src/xfns.c (x_set_scroll_bar_foreground, x_set_scroll_bar_background): Access display hooks through the frame pointer. (Fx_create_frame, x_create_tip_frame): Initialize the frame's display structure. src/xmenu.c: Include termhooks.h after frame.h. src/xselect.c (x_own_selection, some_frame_on_display, x_get_foreign_selection) (Fx_disown_selection_internal, Fx_get_cut_buffer_internal) (Fx_store_cut_buffer_internal, Fx_rotate_cut_buffers_internal): Don't do anything if the selected frame is not an X frame. src/xterm.c (x_display_method): Removed. (x_create_frame_display, x_delete_frame_display): New functions for handling struct display objects. (x_term_init): Set up a new struct display object, too. (x_delete_display): Delete the struct display corresponding to the X display. (x_initialize): Moved hook initialization to x_create_frame_display. src/xterm.h (x_display_method): Removed. (struct x_display_info): Added frame_display component. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-44
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 05 Jan 2004 05:54:35 +0000
parents 695cf19ef79e
children 2fa021a3a2fb 375f2633d815
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42558
4a1e3c7e7dd1 Fix spelling in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 42141
diff changeset
1 ;;; image-file.el --- support for visiting image files
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
2 ;;
35884
3d9c9fe711c4 (insert-image-file): When visiting an image, set `truncate-lines' to t
Miles Bader <miles@gnu.org>
parents: 35854
diff changeset
3 ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
4 ;;
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
5 ;; Author: Miles Bader <miles@gnu.org>
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Keywords: multimedia
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
7
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
9
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; any later version.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
14
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
19
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
24
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
26
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
27 ;; Defines a file-name-handler hook that transforms visited (or
42558
4a1e3c7e7dd1 Fix spelling in comments.
Pavel Janík <Pavel@Janik.cz>
parents: 42141
diff changeset
28 ;; inserted) image files so that they are displayed by Emacs as
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
29 ;; images. This is done by putting a `display' text-property on the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;; image data, with the image-data still present underneath; if the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
31 ;; resulting buffer file is saved to another name it will correctly save
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
32 ;; the image data to the new file.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
33
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
34 ;;; Code:
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
35
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
36 (require 'image)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
37
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
38
32440
4e98e54082d2 (image-file-name-extensions, image-file-name-regexps): Add autoload cookies.
Miles Bader <miles@gnu.org>
parents: 32316
diff changeset
39 ;;;###autoload
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
40 (defcustom image-file-name-extensions
42141
55c0ac959234 (image-file-name-extensions): Add pnm. Doc fix.
Dave Love <fx@gnu.org>
parents: 36213
diff changeset
41 '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm" "xpm" "pbm" "pgm" "ppm" "pnm")
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
42 "*A list of image-file filename extensions.
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
43 Filenames having one of these extensions are considered image files,
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
44 in addition to those matching `image-file-name-regexps'.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
45
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
46 See `auto-image-file-mode'; if `auto-image-file-mode' is enabled,
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
47 setting this variable directly does not take effect unless
42141
55c0ac959234 (image-file-name-extensions): Add pnm. Doc fix.
Dave Love <fx@gnu.org>
parents: 36213
diff changeset
48 `auto-image-file-mode' is re-enabled; this happens automatically when
55c0ac959234 (image-file-name-extensions): Add pnm. Doc fix.
Dave Love <fx@gnu.org>
parents: 36213
diff changeset
49 the variable is set using \\[customize]."
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
50 :type '(repeat string)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
51 :set (lambda (sym val)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
52 (set-default sym val)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
53 (when auto-image-file-mode
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
54 ;; Re-initialize the image-file handler
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
55 (auto-image-file-mode t)))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
56 :initialize 'custom-initialize-default
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
57 :group 'image)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
58
32440
4e98e54082d2 (image-file-name-extensions, image-file-name-regexps): Add autoload cookies.
Miles Bader <miles@gnu.org>
parents: 32316
diff changeset
59 ;;;###autoload
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
60 (defcustom image-file-name-regexps nil
32185
f7460e78c02a Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32003
diff changeset
61 "*List of regexps matching image-file filenames.
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
62 Filenames matching one of these regexps are considered image files,
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
63 in addition to those with an extension in `image-file-name-extensions'.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
64
32220
3c7e4ccb6fee (image-file-name-extensions): Add pbm.
Dave Love <fx@gnu.org>
parents: 32218
diff changeset
65 See function `auto-image-file-mode'; if `auto-image-file-mode' is
3c7e4ccb6fee (image-file-name-extensions): Add pbm.
Dave Love <fx@gnu.org>
parents: 32218
diff changeset
66 enabled, setting this variable directly does not take effect unless
42141
55c0ac959234 (image-file-name-extensions): Add pnm. Doc fix.
Dave Love <fx@gnu.org>
parents: 36213
diff changeset
67 `auto-image-file-mode' is re-enabled; this happens automatically when
55c0ac959234 (image-file-name-extensions): Add pnm. Doc fix.
Dave Love <fx@gnu.org>
parents: 36213
diff changeset
68 the variable is set using \\[customize]."
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
69 :type '(repeat regexp)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
70 :set (lambda (sym val)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
71 (set-default sym val)
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
72 (when auto-image-file-mode
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
73 ;; Re-initialize the image-file handler
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
74 (auto-image-file-mode t)))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
75 :initialize 'custom-initialize-default
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
76 :group 'image)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
77
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
78
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
79 ;;;###autoload
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
80 (defun image-file-name-regexp ()
32185
f7460e78c02a Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32003
diff changeset
81 "Return a regular expression matching image-file filenames."
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
82 (let ((exts-regexp
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
83 (and image-file-name-extensions
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
84 (concat "\\."
34074
89fcace178df (image-file-name-regexp): Automatically add upper-case variants of each
Miles Bader <miles@gnu.org>
parents: 33727
diff changeset
85 (regexp-opt (nconc (mapcar #'upcase
89fcace178df (image-file-name-regexp): Automatically add upper-case variants of each
Miles Bader <miles@gnu.org>
parents: 33727
diff changeset
86 image-file-name-extensions)
89fcace178df (image-file-name-regexp): Automatically add upper-case variants of each
Miles Bader <miles@gnu.org>
parents: 33727
diff changeset
87 image-file-name-extensions)
89fcace178df (image-file-name-regexp): Automatically add upper-case variants of each
Miles Bader <miles@gnu.org>
parents: 33727
diff changeset
88 t)
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
89 "\\'"))))
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
90 (if image-file-name-regexps
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
91 (mapconcat 'identity
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
92 (if exts-regexp
32218
65d06b88701d (image-file-name-regexp): image-file-regexps -> image-file-name-regexps.
Dave Love <fx@gnu.org>
parents: 32185
diff changeset
93 (cons exts-regexp image-file-name-regexps)
65d06b88701d (image-file-name-regexp): image-file-regexps -> image-file-name-regexps.
Dave Love <fx@gnu.org>
parents: 32185
diff changeset
94 image-file-name-regexps)
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
95 "\\|")
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
96 exts-regexp)))
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
97
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
98
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
99 ;;;###autoload
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
100 (defun insert-image-file (file &optional visit beg end replace)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
101 "Insert the image file FILE into the current buffer.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
102 Optional arguments VISIT, BEG, END, and REPLACE are interpreted as for
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
103 the command `insert-file-contents'."
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
104 (let ((rval
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 (image-file-call-underlying #'insert-file-contents-literally
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
106 'insert-file-contents
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
107 file visit beg end replace)))
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
108 ;; Turn the image data into a real image, but only if the whole file
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
109 ;; was inserted
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
110 (when (and (or (null beg) (zerop beg)) (null end))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 (let* ((ibeg (point))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
112 (iend (+ (point) (cadr rval)))
35854
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
113 (visitingp (and visit (= ibeg (point-min)) (= iend (point-max))))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
114 (data
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
115 (string-make-unibyte
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
116 (buffer-substring-no-properties ibeg iend)))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
117 (image
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
118 (create-image data nil t))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
119 (props
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
120 `(display ,image
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
121 intangible ,image
33727
242c7cbf0a6b (insert-image-file): Don't make `read-only' property rear-nonsticky.
Miles Bader <miles@gnu.org>
parents: 33608
diff changeset
122 rear-nonsticky (display intangible)
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
123 ;; This a cheap attempt to make the whole buffer
33727
242c7cbf0a6b (insert-image-file): Don't make `read-only' property rear-nonsticky.
Miles Bader <miles@gnu.org>
parents: 33608
diff changeset
124 ;; read-only when we're visiting the file (as
242c7cbf0a6b (insert-image-file): Don't make `read-only' property rear-nonsticky.
Miles Bader <miles@gnu.org>
parents: 33608
diff changeset
125 ;; opposed to just inserting it).
35854
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
126 ,@(and visitingp
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
127 '(read-only t front-sticky (read-only))))))
35854
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
128 (add-text-properties ibeg iend props)
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
129 (when visitingp
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
130 ;; Inhibit the cursor when the buffer contains only an image,
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
131 ;; because cursors look very strange on top of images.
35884
3d9c9fe711c4 (insert-image-file): When visiting an image, set `truncate-lines' to t
Miles Bader <miles@gnu.org>
parents: 35854
diff changeset
132 (setq cursor-type nil)
3d9c9fe711c4 (insert-image-file): When visiting an image, set `truncate-lines' to t
Miles Bader <miles@gnu.org>
parents: 35854
diff changeset
133 ;; This just makes the arrow displayed in the right fringe
3d9c9fe711c4 (insert-image-file): When visiting an image, set `truncate-lines' to t
Miles Bader <miles@gnu.org>
parents: 35854
diff changeset
134 ;; area look correct when the image is wider than the window.
3d9c9fe711c4 (insert-image-file): When visiting an image, set `truncate-lines' to t
Miles Bader <miles@gnu.org>
parents: 35854
diff changeset
135 (setq truncate-lines t))))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
136 rval))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
137
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
138 (defun image-file-handler (operation &rest args)
32185
f7460e78c02a Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32003
diff changeset
139 "Filename handler for inserting image files.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
140 OPERATION is the operation to perform, on ARGS.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
141 See `file-name-handler-alist' for details."
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
142 (if (and (eq operation 'insert-file-contents)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
143 auto-image-file-mode)
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
144 (apply #'insert-image-file args)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
145 ;; We don't handle OPERATION, use another handler or the default
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
146 (apply #'image-file-call-underlying operation operation args)))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
147
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
148 (defun image-file-call-underlying (function operation &rest args)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
149 "Call FUNCTION with `image-file-handler' and OPERATION inhibited.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
150 Optional argument ARGS are the arguments to call FUNCTION with."
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
151 (let ((inhibit-file-name-handlers
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
152 (cons 'image-file-handler
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
153 (and (eq inhibit-file-name-operation operation)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
154 inhibit-file-name-handlers)))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
155 (inhibit-file-name-operation operation))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
156 (apply function args)))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
157
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
158
32316
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
159 ;;;###autoload
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
160 (define-minor-mode auto-image-file-mode
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
161 "Toggle visiting of image files as images.
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
162 With prefix argument ARG, turn on if positive, otherwise off.
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
163 Returns non-nil if the new state is enabled.
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
164
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
165 Image files are those whose name has an extension in
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
166 `image-file-name-extensions', or matches a regexp in
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
167 `image-file-name-regexps'."
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
168 :global t
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
169 :group 'image
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
170 ;; Remove existing handler
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
171 (let ((existing-entry
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
172 (rassq 'image-file-handler file-name-handler-alist)))
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
173 (when existing-entry
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
174 (setq file-name-handler-alist
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
175 (delq existing-entry file-name-handler-alist))))
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
176 ;; Add new handler, if enabled
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
177 (when auto-image-file-mode
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
178 (push (cons (image-file-name-regexp) 'image-file-handler)
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
179 file-name-handler-alist)))
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
180
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
181
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
182 (provide 'image-file)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
183
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 47862
diff changeset
184 ;;; arch-tag: 04cafe36-f7ba-4c80-9f47-4cb656520ce1
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
185 ;;; image-file.el ends here