changeset 248:b9771459243e dev

Automatic `bb=...' generation for jpg/png/gif/bmp files.
author yuuji@gentei.org
date Fri, 10 Feb 2012 16:45:04 +0900
parents 3e3ccba06ca1
children c2aa2457a74b
files yatexadd.el
diffstat 1 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/yatexadd.el	Fri Feb 10 12:31:58 2012 +0900
+++ b/yatexadd.el	Fri Feb 10 16:45:04 2012 +0900
@@ -2,7 +2,7 @@
 ;;; YaTeX add-in functions.
 ;;; yatexadd.el rev.20
 ;;; (c)1991-2012 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Fri Feb 10 09:50:00 2012 on firestorm
+;;; Last modified Fri Feb 10 16:30:39 2012 on firestorm
 ;;; $Id$
 
 ;;;
@@ -1885,14 +1885,13 @@
 				 (format "%s=%s" s (symbol-value s))))
 			 '(width height scale angle)))
 	   ","))
-    (setq YaTeX-section-name "caption")
     (if (string= "" str) ""
       (concat "[" str "]"))))
 
 (defun YaTeX::includegraphics (argp)
   "Add-in for \\includegraphics"
   (let ((imgfile (YaTeX::include argp "Image File: "))
-	(case-fold-search t) info bb)
+	(case-fold-search t) info bb noupdate needclose)
     (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile)
 	 (file-exists-p imgfile)
 	 (or (fboundp 'yahtml-get-image-info)
@@ -1902,7 +1901,29 @@
 	 (car info)			;if has width value
 	 (car (cdr info))		;if has height value
 	 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info))))
-	 (YaTeX-push-to-kill-ring bb))
+	 (save-excursion
+	   (cond
+	    ((and (YaTeX-re-search-active-backward
+		   "\\\\\\(includegraphics\\)\\|\\(bb=[ \t0-9]+\\)"
+		   YaTeX-comment-prefix nil t)
+		  (match-beginning 2)
+		  (not (setq noupdate (equal (YaTeX-match-string 2) bb)))
+		  (y-or-n-p (format "Update `bb=' line to `%s'?: " bb)))
+	     (message "")
+	     (replace-match bb))
+	    (noupdate nil)
+	    ((and (match-beginning 1)
+		  (y-or-n-p "Insert `bb=...' line?: "))
+	     (goto-char (match-end 0))
+	     (message "")
+	     (if (looking-at "\\[") (forward-char 1)
+	       (insert-before-markers "[")
+	       (setq needclose t))
+	     (insert-before-markers bb)
+	     (if needclose (insert-before-markers "]")
+	       (or (looking-at "\\]") (insert-before-markers ","))))
+	    (t (YaTeX-push-to-kill-ring bb)))))
+    (setq YaTeX-section-name "caption")
     imgfile))
  
 (defun YaTeX::verbfile (argp)

yatex.org