annotate lisp/image-file.el @ 110523:a5ad4f188e19

Synch Semantic to CEDET 1.0. Move CEDET ChangeLog entries to new file lisp/cedet/ChangeLog. * semantic.el (semantic-version): Update to 2.0. (semantic-mode-map): Add "," and "m" bindings. (navigate-menu): Update. * semantic/symref.el (semantic-symref-calculate-rootdir): New function. (semantic-symref-detect-symref-tool): Use it. * semantic/symref/grep.el (semantic-symref-grep-shell): New var. (semantic-symref-perform-search): Use it. Calculate root dir with semantic-symref-calculate-rootdir. (semantic-symref-derive-find-filepatterns): Improve error message. * semantic/symref/list.el (semantic-symref-results-mode-map): New bindings. (semantic-symref-auto-expand-results): New option. (semantic-symref-results-dump): Obey auto-expand. (semantic-symref-list-expand-all, semantic-symref-regexp) (semantic-symref-list-contract-all) (semantic-symref-list-map-open-hits) (semantic-symref-list-update-open-hits) (semantic-symref-list-create-macro-on-open-hit) (semantic-symref-list-call-macro-on-open-hits): New functions. (semantic-symref-list-menu-entries) (semantic-symref-list-menu): New vars. (semantic-symref-list-map-open-hits): Move cursor to beginning of match before calling the mapped function. * semantic/doc.el (semantic-documentation-comment-preceeding-tag): Do nothing if the mode doesn't provide comment-start-skip. * semantic/scope.el (semantic-analyze-scope-nested-tags-default): Strip duplicates. (semantic-analyze-scoped-inherited-tag-map): Take the tag we are looking for as part of the scoped tags list. * semantic/html.el (semantic-default-html-setup): Add senator-step-at-tag-classes. * semantic/decorate/include.el (semantic-decoration-on-unknown-includes): Change light bgcolor. (semantic-decoration-on-includes-highlight-default): Check that the include tag has a postion. * semantic/complete.el (semantic-collector-local-members): (semantic-complete-read-tag-local-members) (semantic-complete-jump-local-members): New class and functions. (semantic-complete-self-insert): Save excursion before completing. * semantic/analyze/complete.el (semantic-analyze-possible-completions-default): If no completions are found, return the raw by-name-only completion list. Add FLAGS arguments. Add support for 'no-tc (type constraint) and 'no-unique, or no stripping duplicates. (semantic-analyze-possible-completions-default): Add FLAGS arg. * semantic/util-modes.el (semantic-stickyfunc-show-only-functions-p): New option. (semantic-stickyfunc-fetch-stickyline): Don't show stickytext for the very first line in a buffer. * semantic/util.el (semantic-hack-search) (semantic-recursive-find-nonterminal-by-name) (semantic-current-tag-interactive): Deleted. (semantic-describe-buffer): Fix expand-nonterminal. Add lex-syntax-mods, type relation separator char, and command separation char. (semantic-sanity-check): Only message if called interactively. * semantic/tag.el (semantic-tag-deep-copy-one-tag): Copy the :filename property and the tag position. * semantic/lex-spp.el (semantic-lex-spp-lex-text-string): Add recursion limit. * semantic/imenu.el (semantic-imenu-bucketize-type-members): Make this buffer local, not the obsoleted variable. * semantic/idle.el: Add breadcrumbs support. (semantic-idle-summary-current-symbol-info-default) (semantic-idle-tag-highlight) (semantic-idle-completion-list-default): Use semanticdb-without-unloaded-file-searches for speed, and to conform to the controls that specify if the idle timer is supposed to be parsing unparsed includes. (semantic-idle-symbol-highlight-face) (semantic-idle-symbol-maybe-highlight): Rename from *-summary-*. Callers changed. (semantic-idle-work-parse-neighboring-files-flag): Default to nil. (semantic-idle-work-update-headers-flag): New var. (semantic-idle-work-for-one-buffer): Use it. (semantic-idle-local-symbol-highlight): Rename from semantic-idle-tag-highlight. (semantic-idle-truncate-long-summaries): New option. * semantic/ia.el (semantic-ia-cache) (semantic-ia-get-completions): Deleted. Callers changed. (semantic-ia-show-variants): New command. (semantic-ia-show-doc): If doc is empty, don't make a temp buffer. (semantic-ia-show-summary): If there isn't anything to show, say so. * semantic/grammar.el (semantic-grammar-create-package): Save the buffer even in batch mode. * semantic/fw.el (semanticdb-without-unloaded-file-searches): New macro. * semantic/dep.el (semantic-dependency-find-file-on-path): Fix case dereferencing ede-object when it is a list. * semantic/db-typecache.el (semanticdb-expand-nested-tag) (semanticdb-typecache-faux-namespace): New functions. (semanticdb-typecache-file-tags) (semanticdb-typecache-merge-streams): Use them. (semanticdb-typecache-file-tags): When deriving tags from a file, give the mode a chance to monkey with the tag copy. (semanticdb-typecache-find-default): Wrap find in save-excursion. (semanticdb-typecache-find-by-name-helper): Merge found names down. * semantic/db-global.el (semanticdb-enable-gnu-global-in-buffer): Don't show messages if GNU Global is not available and we don't want to throw an error. * semantic/db-find.el (semanticdb-find-result-nth-in-buffer): When trying to normalize the tag to a buffer, don't error if set-buffer method doesn't exist. * semantic/db-file.el (semanticdb-save-db): Simplify msg. * semantic/db.el (semanticdb-refresh-table): If forcing a refresh on a file not in a buffer, use semantic-find-file-noselect and delete the buffer after use. (semanticdb-current-database-list): When calculating root via hooks, force it through true-filename and skip the list of possible roots. * semantic/ctxt.el (semantic-ctxt-imported-packages): New. * semantic/analyze/debug.el (semantic-analyzer-debug-insert-tag): Reset standard output to current buffer. (semantic-analyzer-debug-global-symbol) (semantic-analyzer-debug-missing-innertype): Change "prefix" to "symbol" in messages. * semantic/analyze/refs.el: (semantic-analyze-refs-impl) (semantic-analyze-refs-proto): When calculating value, make sure the found tag is 'similar' to the originating tag. (semantic--analyze-refs-find-tags-with-parent): Attempt to identify matches via imported symbols of parents. (semantic--analyze-refs-full-lookup-with-parents): Do a deep search during the brute search. * semantic/analyze.el (semantic-analyze-find-tag-sequence-default): Be robust to calculated scopes being nil. * semantic/bovine/c.el (semantic-c-describe-environment): Add project macro symbol array. (semantic-c-parse-lexical-token): Add recursion limit. (semantic-ctxt-imported-packages, semanticdb-expand-nested-tag): New overrides. (semantic-expand-c-tag-namelist): Split a full type from a typedef out to its own tag. (semantic-expand-c-tag-namelist): Do not split out a typedef'd inline type if it is an anonymous type. (semantic-c-reconstitute-token): Use the optional initializers as a clue that some function is probably a constructor. When defining the type of these constructors, split the parent name, and use only the class part, if applicable. * semantic/bovine/c-by.el: * semantic/wisent/python-wy.el: Regenerate.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 18 Sep 2010 22:49:54 -0400
parents 1d1d5d9bd884
children 376148b31b5e
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 ;;
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64594
diff changeset
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105870
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
5 ;;
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Author: Miles Bader <miles@gnu.org>
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
7 ;; Keywords: multimedia
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
8
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
10
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
15
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
20
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
23
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
25
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
26 ;; 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
27 ;; inserted) image files so that they are displayed by Emacs as
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
28 ;; images. This is done by putting a `display' text-property on the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
29 ;; image data, with the image-data still present underneath; if the
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;; resulting buffer file is saved to another name it will correctly save
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
31 ;; the image data to the new file.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
32
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
33 ;;; Code:
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
34
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
35 (require 'image)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
36
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
37
32440
4e98e54082d2 (image-file-name-extensions, image-file-name-regexps): Add autoload cookies.
Miles Bader <miles@gnu.org>
parents: 32316
diff changeset
38 ;;;###autoload
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
39 (defcustom image-file-name-extensions
105870
26baacb565b0 * textmodes/tex-mode.el (tex-alt-dvi-print-command)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 100908
diff changeset
40 (purecopy '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm" "xpm" "pbm" "pgm" "ppm" "pnm" "svg"))
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 94678
diff changeset
41 "A list of image-file filename extensions.
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
42 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
43 in addition to those matching `image-file-name-regexps'.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
44
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
45 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
46 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
47 `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
48 the variable is set using \\[customize]."
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
49 :type '(repeat string)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
50 :set (lambda (sym val)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
51 (set-default sym val)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
52 (when auto-image-file-mode
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
53 ;; Re-initialize the image-file handler
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
54 (auto-image-file-mode t)))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
55 :initialize 'custom-initialize-default
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
56 :group 'image)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
57
32440
4e98e54082d2 (image-file-name-extensions, image-file-name-regexps): Add autoload cookies.
Miles Bader <miles@gnu.org>
parents: 32316
diff changeset
58 ;;;###autoload
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
59 (defcustom image-file-name-regexps nil
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 94678
diff changeset
60 "List of regexps matching image-file filenames.
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
61 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
62 in addition to those with an extension in `image-file-name-extensions'.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
63
32220
3c7e4ccb6fee (image-file-name-extensions): Add pbm.
Dave Love <fx@gnu.org>
parents: 32218
diff changeset
64 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
65 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
66 `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
67 the variable is set using \\[customize]."
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
68 :type '(repeat regexp)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
69 :set (lambda (sym val)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
70 (set-default sym val)
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
71 (when auto-image-file-mode
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
72 ;; Re-initialize the image-file handler
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
73 (auto-image-file-mode t)))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
74 :initialize 'custom-initialize-default
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
75 :group 'image)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
76
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
77
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
78 ;;;###autoload
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
79 (defun image-file-name-regexp ()
32185
f7460e78c02a Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32003
diff changeset
80 "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
81 (let ((exts-regexp
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
82 (and image-file-name-extensions
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
83 (concat "\\."
34074
89fcace178df (image-file-name-regexp): Automatically add upper-case variants of each
Miles Bader <miles@gnu.org>
parents: 33727
diff changeset
84 (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
85 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
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 t)
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
88 "\\'"))))
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
89 (if image-file-name-regexps
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
90 (mapconcat 'identity
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
91 (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
92 (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
93 image-file-name-regexps)
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
94 "\\|")
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
95 exts-regexp)))
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
96
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 ;;;###autoload
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
99 (defun insert-image-file (file &optional visit beg end replace)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
100 "Insert the image file FILE into the current buffer.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
101 Optional arguments VISIT, BEG, END, and REPLACE are interpreted as for
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
102 the command `insert-file-contents'."
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
103 (let ((rval
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
104 (image-file-call-underlying #'insert-file-contents-literally
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 'insert-file-contents
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
106 file visit beg end replace)))
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
107 ;; 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
108 ;; was inserted
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
109 (when (and (or (null beg) (zerop beg)) (null end))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
110 (let* ((ibeg (point))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 (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
112 (visitingp (and visit (= ibeg (point-min)) (= iend (point-max))))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
113 (data
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
114 (string-make-unibyte
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
115 (buffer-substring-no-properties ibeg iend)))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
116 (image
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
117 (create-image data nil t))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
118 (props
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
119 `(display ,image
64594
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
120 yank-handler
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
121 (image-file-yank-handler nil t)
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
122 intangible ,image
33727
242c7cbf0a6b (insert-image-file): Don't make `read-only' property rear-nonsticky.
Miles Bader <miles@gnu.org>
parents: 33608
diff changeset
123 rear-nonsticky (display intangible)
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
124 ;; 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
125 ;; 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
126 ;; 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
127 ,@(and visitingp
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
128 '(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
129 (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
130 (when visitingp
a8fd9112792b (insert-image-file): When visiting an image, suppress the cursor in the
Miles Bader <miles@gnu.org>
parents: 34650
diff changeset
131 ;; 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
132 ;; 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
133 (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
134 ;; 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
135 ;; 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
136 (setq truncate-lines t))))
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
137 rval))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
138
64556
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
139 ;; We use a yank-handler to make yanked images unique, so that
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
140 ;; yanking two copies of the same image next to each other are
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
141 ;; recognized as two different images.
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
142 (defun image-file-yank-handler (string)
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
143 "Yank handler for inserting an image into a buffer."
64594
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
144 (let ((len (length string))
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
145 (image (get-text-property 0 'display string)))
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
146 (remove-text-properties 0 len yank-excluded-properties string)
64556
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
147 (if (consp image)
64594
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
148 (add-text-properties 0
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
149 (or (next-single-property-change 0 'image-counter string)
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
150 (length string))
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
151 `(display
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
152 ,(cons (car image) (cdr image))
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
153 yank-handler
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
154 ,(cons 'image-file-yank-handler '(nil t)))
7a0be66e1adb (insert-image-file, image-file-yank-handler): Fix
Kim F. Storm <storm@cua.dk>
parents: 64556
diff changeset
155 string))
64556
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
156 (insert string)))
a0c4a6096f55 (insert-image-file): Add yank-handler.
Kim F. Storm <storm@cua.dk>
parents: 64091
diff changeset
157
60523
2fa021a3a2fb (image-file-handler): Put `safe-magic' property to
Juri Linkov <juri@jurta.org>
parents: 52401
diff changeset
158 (put 'image-file-handler 'safe-magic t)
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
159 (defun image-file-handler (operation &rest args)
32185
f7460e78c02a Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32003
diff changeset
160 "Filename handler for inserting image files.
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
161 OPERATION is the operation to perform, on ARGS.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
162 See `file-name-handler-alist' for details."
32003
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
163 (if (and (eq operation 'insert-file-contents)
ff2dfe1f1df9 (image-file-name-extensions): New variable.
Miles Bader <miles@gnu.org>
parents: 31934
diff changeset
164 auto-image-file-mode)
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
165 (apply #'insert-image-file args)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
166 ;; We don't handle OPERATION, use another handler or the default
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
167 (apply #'image-file-call-underlying operation operation args)))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
168
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
169 (defun image-file-call-underlying (function operation &rest args)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
170 "Call FUNCTION with `image-file-handler' and OPERATION inhibited.
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
171 Optional argument ARGS are the arguments to call FUNCTION with."
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
172 (let ((inhibit-file-name-handlers
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
173 (cons 'image-file-handler
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
174 (and (eq inhibit-file-name-operation operation)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
175 inhibit-file-name-handlers)))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
176 (inhibit-file-name-operation operation))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
177 (apply function args)))
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
178
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
179
32316
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
180 ;;;###autoload
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
181 (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
182 "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
183 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
184 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
185
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
186 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
187 `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
188 `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
189 :global t
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
190 :group 'image
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
191 ;; 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
192 (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
193 (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
194 (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
195 (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
196 (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
197 ;; 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
198 (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
199 (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
200 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
201
b930d561cd53 (auto-image-file-mode): Move to the end of the file, because
Miles Bader <miles@gnu.org>
parents: 32220
diff changeset
202
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
203 (provide 'image-file)
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
204
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
205 ;; arch-tag: 04cafe36-f7ba-4c80-9f47-4cb656520ce1
31934
27f239b438d2 Initial checkin.
Miles Bader <miles@gnu.org>
parents:
diff changeset
206 ;;; image-file.el ends here