# HG changeset patch # User HIROSE Yuuji # Date 1418910948 -32400 # Node ID 43fb2bf403e4298edcfb2d0684ea970748fbe7c0 # Parent 90bdb4173c970d1162a64f4aa8511f969d0b4269 Set undo-boundary for quick modification by user. diff -r 90bdb4173c97 -r 43fb2bf403e4 yatex23.el --- a/yatex23.el Thu Dec 18 22:54:48 2014 +0900 +++ b/yatex23.el Thu Dec 18 22:55:48 2014 +0900 @@ -1,30 +1,82 @@ ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*- ;;; (c)2014 by HIROSE Yuuji.[yuuji@yatex.org] -;;; Last modified Tue Dec 16 11:29:14 2014 on firestorm +;;; Last modified Thu Dec 18 18:26:55 2014 on firestorm ;;; $Id:$ ;;; Code: +(defvar YaTeX-dnd-auto-figure "figure" + "*If set, include dropped \\includegraphcs{} into that environment. +The value should be string. Set this `nil' to disable enclosing.") (defun YaTeX-dnd-handler (uri action) "DnD handler for yatex-mode Convert local image URI to \\includegraphcis{} and .tex file names to \\include{}." - (save-excursion - (YaTeX-visit-main t) - (let*((file (dnd-get-local-file-name uri)) - (path (file-relative-name file)) - (insert-file-directory nil) - (case-fold-search t)) + (let*((file (dnd-get-local-file-name uri)) + (path (save-excursion + (YaTeX-visit-main t) + (file-relative-name file))) + (insert-file-directory nil) + (case-fold-search t) + (b nil) p1 p2 (cc (current-column)) envstart) + (cond + ((memq action '(copy link move private)) (cond - ((memq action '(copy link move private)) - (cond - ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path) - (insert "\\includegraphics") - (insert "{" (YaTeX::includegraphics 1 path t) "}") - (YaTeX-package-auto-usepackage "includegraphics" 'section)) - ((string-match "\\.tex$" path) - (insert "\\include{" path "}")) - )) - (t (message "%s" action)))))) + ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path) + (if (and (stringp YaTeX-dnd-auto-figure) + (not (YaTeX-in-environment-p YaTeX-dnd-auto-figure)) + (not (string-match "figure" + (or (YaTeX-inner-environment t) "body"))) + YaTeX-dnd-auto-figure) + (setq b (format "\\begin{%s}[htbp] %%\\centering\n" + YaTeX-dnd-auto-figure))) + (unwind-protect + (progn + (setq envstart (point-marker)) + (insert "\\includegraphics") + (insert "{" (YaTeX::includegraphics 1 path t) "}") + (save-excursion + (YaTeX-package-auto-usepackage "includegraphics" 'section)) + (cond + (b + (undo-boundary) + (save-excursion + (goto-char envstart) + (insert b)) + (YaTeX-indent-line) + (insert "\n") + (indent-to (1+ cc)) + (setq p1 (point)) + (insert "\\caption{") + (setq p2 (point)) + (insert (format "}\\label{%s}\n" path)) + (indent-to cc) + (insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure)) + (goto-char p2) + (undo-boundary) + (insert (file-name-nondirectory path)) + (undo-boundary) + (goto-char p1) + (insert "%") + (end-of-line) + (or (get 'YaTeX-dnd-auto-figure 'guide) + (progn + (newline 1) + (indent-to (1+ cc)) + (insert (format + (if YaTeX-japan + "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境" + "%% TYPE undo(%s) to ACTIVATE caption. Twice to clear caption. 3 to no-env") + (key-description + (car (where-is-internal 'undo))))) + (put 'YaTeX-dnd-auto-figure 'guide t))))) + (YaTeX-help "includegraphics") + ) + (set-marker envstart nil) ;;sure to reset marker + action)) + ((string-match "\\.tex$" path) + (insert "\\include{" path "}")) + )) + (t (message "%s" action))))) (provide 'yatex23)