yatex

view yatex23.el @ 357:4ea63809a0ca

Insert `\includegraphics[dvipdfmx]{graphics}' without query
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 22 Dec 2014 11:16:46 +0900
parents 3478a327ae41
children 2c2b70f41fb3
line source
1 ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*-
2 ;;; (c)2014 by HIROSE Yuuji.[yuuji@yatex.org]
3 ;;; Last modified Mon Dec 22 11:15:48 2014 on firestorm
4 ;;; $Id:$
6 ;;; Code:
7 (defvar YaTeX-dnd-auto-figure "figure"
8 "*If set, include dropped \\includegraphcs{} into that environment.
9 The value should be string. Set this `nil' to disable enclosing.")
10 (defun YaTeX-dnd-handler (uri action)
11 "DnD handler for yatex-mode
12 Convert local image URI to \\includegraphcis{} and
13 .tex file names to \\include{}."
14 (let*((file (dnd-get-local-file-name uri))
15 (path (save-excursion
16 (YaTeX-visit-main t)
17 (file-relative-name file)))
18 (insert-file-directory nil)
19 (case-fold-search t)
20 (b nil) p1 p2 (cc (current-column)) envstart)
21 (cond
22 ((memq action '(copy link move private))
23 (cond
24 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path)
25 (if (and (stringp YaTeX-dnd-auto-figure)
26 (not (YaTeX-in-environment-p YaTeX-dnd-auto-figure))
27 (not (string-match "figure"
28 (or (YaTeX-inner-environment t) "body")))
29 YaTeX-dnd-auto-figure)
30 (setq b (format "\\begin{%s}[htbp] %%\\centering\n"
31 YaTeX-dnd-auto-figure)))
32 (unwind-protect
33 (progn
34 (setq envstart (point-marker))
35 (insert "\\includegraphics")
36 (insert "{" (YaTeX::includegraphics 1 path t) "}")
37 (save-excursion
38 (YaTeX-package-auto-usepackage
39 "includegraphics" 'section "graphicx" "dvipdfmx"))
40 (cond
41 (b
42 (undo-boundary)
43 (save-excursion
44 (goto-char envstart)
45 (insert b))
46 (YaTeX-indent-line)
47 (insert "\n")
48 (indent-to (1+ cc))
49 (setq p1 (point))
50 (insert "\\caption{")
51 (setq p2 (point))
52 (insert (format "}\\label{%s}\n" path))
53 (indent-to cc)
54 (insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure))
55 (goto-char p2)
56 (undo-boundary)
57 (insert (file-name-nondirectory path))
58 (undo-boundary)
59 (goto-char p1)
60 (insert "%")
61 (end-of-line)
62 (or (get 'YaTeX-dnd-auto-figure 'guide)
63 (progn
64 (newline 1)
65 (indent-to (1+ cc))
66 (insert (format
67 (if YaTeX-japan
68 "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境"
69 "%% TYPE undo(%s) to ACTIVATE caption. Twice to clear caption. 3 to no-env")
70 (key-description
71 (car (where-is-internal 'undo)))))
72 (put 'YaTeX-dnd-auto-figure 'guide t)))))
73 (YaTeX-help "includegraphics"))
74 (set-marker envstart nil) ;;sure to reset marker
75 action))
76 ((string-match "\\(.*\\)\\.tex$" path)
77 (insert "\\include{" (match-string 1 path) "}"))
78 ((string-match "\\(.*\\)\\.bib$" path)
79 (insert "\\bibliography{" (match-string 1 path) "}"))
80 ((string-match "\\.ind$" path)
81 (insert "\\input{" path "}"))))
82 (t (message "%s" action)))))
84 (provide 'yatex23)
86 ; Local variables:
87 ; fill-prefix: ";;; "
88 ; paragraph-start: "^$\\| \\|;;;$"
89 ; paragraph-separate: "^$\\| \\|;;;$"
90 ; coding: sjis
91 ; End: