yatex / yatex23.el
@HIROSE Yuuji HIROSE Yuuji on 20 Dec 2014 2 KB DnD *.ind and *.big file
;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*-
;;; (c)2014 by HIROSE Yuuji.[]
;;; Last modified Fri Dec 19 21:43:54 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{}."
  (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)
     ((memq action '(copy link move private))
       ((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")))
	    (setq b (format "\\begin{%s}[htbp] %%\\centering\n"
	      (setq envstart (point-marker))
	      (insert "\\includegraphics")
	      (insert "{" (YaTeX::includegraphics 1 path t) "}")
		(YaTeX-package-auto-usepackage "includegraphics" 'section))
		  (goto-char envstart)
		  (insert b))
		(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)
		(insert (file-name-nondirectory path))
		(goto-char p1)
		(insert "%")
		(or (get 'YaTeX-dnd-auto-figure 'guide)
		      (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")
				(car (where-is-internal 'undo)))))
		      (put 'YaTeX-dnd-auto-figure 'guide t)))))
	      (YaTeX-help "includegraphics"))
	  (set-marker envstart nil) ;;sure to reset marker
       ((string-match "\\(.*\\)\\.tex$" path)
	(insert "\\include{" (match-string 1 path) "}"))
       ((string-match "\\(.*\\)\\.bib$" path)
	(insert "\\bibliography{" (match-string 1 path) "}"))
       ((string-match "\\.ind$" path)
	(insert "\\input{" path "}"))))
     (t (message "%s" action)))))

(provide 'yatex23)
; Local variables:
; fill-prefix: ";;; "
; paragraph-start: "^$\\|\\|;;;$"
; paragraph-separate: "^$\\|\\|;;;$"
; coding: sjis
; End: