yatex

changeset 343:43fb2bf403e4 dev

Set undo-boundary for quick modification by user.
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 18 Dec 2014 22:55:48 +0900
parents 90bdb4173c97
children bfd7a5998555
files yatex23.el
diffstat 1 files changed, 69 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/yatex23.el	Thu Dec 18 22:54:48 2014 +0900
     1.2 +++ b/yatex23.el	Thu Dec 18 22:55:48 2014 +0900
     1.3 @@ -1,30 +1,82 @@
     1.4  ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*-
     1.5  ;;; (c)2014 by HIROSE Yuuji.[yuuji@yatex.org]
     1.6 -;;; Last modified Tue Dec 16 11:29:14 2014 on firestorm
     1.7 +;;; Last modified Thu Dec 18 18:26:55 2014 on firestorm
     1.8  ;;; $Id:$
     1.9  
    1.10  ;;; Code:
    1.11 +(defvar YaTeX-dnd-auto-figure "figure"
    1.12 +  "*If set, include dropped \\includegraphcs{} into that environment.
    1.13 +The value should be string.  Set this `nil' to disable enclosing.")
    1.14  (defun YaTeX-dnd-handler (uri action)
    1.15    "DnD handler for yatex-mode
    1.16  Convert local image URI to \\includegraphcis{} and
    1.17  .tex file names to \\include{}."
    1.18 -  (save-excursion
    1.19 -    (YaTeX-visit-main t)
    1.20 -    (let*((file (dnd-get-local-file-name uri))
    1.21 -	  (path (file-relative-name file))
    1.22 -	  (insert-file-directory nil)
    1.23 -	  (case-fold-search t))
    1.24 +  (let*((file (dnd-get-local-file-name uri))
    1.25 +	(path (save-excursion
    1.26 +		(YaTeX-visit-main t)
    1.27 +		(file-relative-name file)))
    1.28 +	(insert-file-directory nil)
    1.29 +	(case-fold-search t)
    1.30 +	(b nil) p1 p2 (cc (current-column)) envstart)
    1.31 +    (cond
    1.32 +     ((memq action '(copy link move private))
    1.33        (cond
    1.34 -       ((memq action '(copy link move private))
    1.35 -	(cond
    1.36 -	 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path)
    1.37 -	  (insert "\\includegraphics")
    1.38 -	  (insert "{" (YaTeX::includegraphics 1 path t) "}")
    1.39 -	  (YaTeX-package-auto-usepackage "includegraphics" 'section))
    1.40 -	 ((string-match "\\.tex$" path)
    1.41 -	  (insert "\\include{" path "}"))
    1.42 -	 ))
    1.43 -       (t (message "%s" action))))))
    1.44 +       ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path)
    1.45 +	(if (and (stringp YaTeX-dnd-auto-figure)
    1.46 +		 (not (YaTeX-in-environment-p YaTeX-dnd-auto-figure))
    1.47 +		 (not (string-match "figure"
    1.48 +				    (or (YaTeX-inner-environment t) "body")))
    1.49 +		 YaTeX-dnd-auto-figure)
    1.50 +	    (setq b (format "\\begin{%s}[htbp] %%\\centering\n"
    1.51 +			    YaTeX-dnd-auto-figure)))
    1.52 +	(unwind-protect
    1.53 +	    (progn
    1.54 +	      (setq envstart (point-marker))
    1.55 +	      (insert "\\includegraphics")
    1.56 +	      (insert "{" (YaTeX::includegraphics 1 path t) "}")
    1.57 +	      (save-excursion
    1.58 +		(YaTeX-package-auto-usepackage "includegraphics" 'section))
    1.59 +	      (cond
    1.60 +	       (b
    1.61 +		(undo-boundary)
    1.62 +		(save-excursion
    1.63 +		  (goto-char envstart)
    1.64 +		  (insert b))
    1.65 +		(YaTeX-indent-line)
    1.66 +		(insert "\n")
    1.67 +		(indent-to (1+ cc))
    1.68 +		(setq p1 (point))
    1.69 +		(insert "\\caption{")
    1.70 +		(setq p2 (point))
    1.71 +		(insert (format "}\\label{%s}\n" path))
    1.72 +		(indent-to cc)
    1.73 +		(insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure))
    1.74 +		(goto-char p2)
    1.75 +		(undo-boundary)
    1.76 +		(insert (file-name-nondirectory path))
    1.77 +		(undo-boundary)
    1.78 +		(goto-char p1)
    1.79 +		(insert "%")
    1.80 +		(end-of-line)
    1.81 +		(or (get 'YaTeX-dnd-auto-figure 'guide)
    1.82 +		    (progn
    1.83 +		      (newline 1)
    1.84 +		      (indent-to (1+ cc))
    1.85 +		      (insert (format
    1.86 +			       (if YaTeX-japan
    1.87 +				   "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境"
    1.88 +				 "%% TYPE undo(%s) to ACTIVATE caption.  Twice to clear caption. 3 to no-env")
    1.89 +			       (key-description
    1.90 +				(car (where-is-internal 'undo)))))
    1.91 +		      (put 'YaTeX-dnd-auto-figure 'guide t)))))
    1.92 +	      (YaTeX-help "includegraphics")
    1.93 +	      )
    1.94 +	  (set-marker envstart nil) ;;sure to reset marker
    1.95 +	  action))
    1.96 +       ((string-match "\\.tex$" path)
    1.97 +	(insert "\\include{" path "}"))
    1.98 +       ))
    1.99 +     (t (message "%s" action)))))
   1.100  
   1.101  (provide 'yatex23)
   1.102