From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.emacs.devel Subject: [PATCH]: images for info Date: Mon, 21 Apr 2003 18:59:54 +0200 Organization: Jan at Appel Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87fzobkcqd.fsf@peder.flower> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1050944521 12824 80.91.224.249 (21 Apr 2003 17:02:01 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Apr 2003 17:02:01 +0000 (UTC) Cc: karl@freefriends.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Apr 21 19:01:59 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 197eey-0003GM-00 for ; Mon, 21 Apr 2003 19:00:52 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 197ejp-0008Ep-00 for ; Mon, 21 Apr 2003 19:05:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 197ef1-00024c-05 for emacs-devel@quimby.gnus.org; Mon, 21 Apr 2003 13:00:56 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 197eeV-0001pb-00 for emacs-devel@gnu.org; Mon, 21 Apr 2003 13:00:23 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 197eeH-0001Tw-00 for emacs-devel@gnu.org; Mon, 21 Apr 2003 13:00:13 -0400 Original-Received: from node-d-3053.a2000.nl ([62.195.48.83] helo=peder.flower) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 197eeB-0001PR-00 for emacs-devel@gnu.org; Mon, 21 Apr 2003 13:00:04 -0400 Original-Received: from localhost ([127.0.0.1] helo=peder.flower ident=janneke) by peder.flower with esmtp (Exim 3.36 #1 (Debian)) id 197ee3-0007ta-00; Mon, 21 Apr 2003 18:59:55 +0200 Original-To: emacs-devel@gnu.org User-Agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:13328 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:13328 This weekend, Karl has installed my patch to texinfo to make makeinfo write image information to info files. From NEWS: . makeinfo writes a new construct for @image to the info file, so that graphical browsers (such as Emacs Info under X) can display an actual image. Thus, a .txt file substitute is no longer included if a real image file is available. Below is an accompanying patch to emacs' info mode. The patches and a small test are also available from http://lilypond.org/~jan/info-image Greetings, Jan. Index: lisp/ChangeLog =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v retrieving revision 1.5053 diff -p -u -r1.5053 ChangeLog --- lisp/ChangeLog 21 Apr 2003 15:43:02 -0000 1.5053 +++ lisp/ChangeLog 21 Apr 2003 16:46:38 -0000 @@ -1,3 +1,10 @@ +2003-04-21 Jan Nieuwenhuizen + + * info.el (Info-unescape-quotes) + (Info-split-parameter-string) + (Info-display-images-node): New functions for displaying images. + (Info-select-node): Call Info-display-images-node. + 2003-04-20 Richard M. Stallman * simple.el (kill-line): Doc fix. Index: lisp/info.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/info.el,v retrieving revision 1.342 diff -p -u -r1.342 info.el --- lisp/info.el 5 Apr 2003 18:01:14 -0000 1.342 +++ lisp/info.el 21 Apr 2003 16:46:40 -0000 @@ -1064,6 +1064,59 @@ a case-insensitive match is tried." (if (numberp nodepos) (+ (- nodepos lastfilepos) (point))))) +(defun Info-unescape-quotes (value) + "Unescape double quotes and backslashes in VALUE" + (let ((start 0) + (unquote value)) + (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start) + (setq unquote (replace-match "" t t unquote 1)) + (setq start (- (match-end 0) 1))) + unquote)) + +(defun Info-split-parameter-string (parameter-string) + "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a + whitespace separated list of KEY=VALUE pairs. If VALUE + contains whitespace or double quotes, it must be quoted in + double quotes and any double quotes or backslashes must be + escaped (\\\",\\\\)." + (let ((start 0) + (parameter-alist)) + (while (string-match + "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)" + parameter-string start) + (setq start (match-end 0)) + (push (cons (match-string 1 parameter-string) + (or (match-string 2 parameter-string) + (Info-unescape-quotes + (match-string 3 parameter-string)))) + parameter-alist)) + parameter-alist)) + +(defun Info-display-images-node () + "Display images in current node." + (save-excursion + (let ((inhibit-read-only t) + (case-fold-search t) + paragraph-markers) + (goto-char (point-min)) + (while (re-search-forward + "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)" + nil t) + (let* ((start (match-beginning 1)) + (parameter-alist (Info-split-parameter-string (match-string 2))) + (src (cdr (assoc-string "src" parameter-alist))) + (image-file (if src (if (file-name-absolute-p src) src + (concat default-directory src)) + "")) + (image (if (file-exists-p image-file) + (create-image image-file) + "[broken image]"))) + (message "Found image: %S" image-file) + (if (not (get-text-property start 'display)) + (add-text-properties + start (point) `(display ,image rear-nonsticky (display))))))) + (set-buffer-modified-p nil))) + (defvar Info-header-line nil "If the info node header is hidden, the text of the header.") (put 'Info-header-line 'risky-local-variable t) @@ -1104,6 +1157,7 @@ Bind this in case the user sets it to ni (if Info-enable-active-nodes (eval active-expression)) (Info-fontify-node) (setq Info-header-line (get-text-property (point-min) 'header-line)) + (Info-display-images-node) (run-hooks 'Info-selection-hook))))) (defun Info-set-mode-line () -- Jan Nieuwenhuizen | GNU LilyPond - The music typesetter http://www.xs4all.nl/~jantien | http://www.lilypond.org