yatex

view yatex23.el @ 343:43fb2bf403e4

Set undo-boundary for quick modification by user.
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 18 Dec 2014 22:55:48 +0900
parents d9c547265e6e
children bfd7a5998555
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 Thu Dec 18 18:26:55 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 "includegraphics" 'section))
39 (cond
40 (b
41 (undo-boundary)
42 (save-excursion
43 (goto-char envstart)
44 (insert b))
45 (YaTeX-indent-line)
46 (insert "\n")
47 (indent-to (1+ cc))
48 (setq p1 (point))
49 (insert "\\caption{")
50 (setq p2 (point))
51 (insert (format "}\\label{%s}\n" path))
52 (indent-to cc)
53 (insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure))
54 (goto-char p2)
55 (undo-boundary)
56 (insert (file-name-nondirectory path))
57 (undo-boundary)
58 (goto-char p1)
59 (insert "%")
60 (end-of-line)
61 (or (get 'YaTeX-dnd-auto-figure 'guide)
62 (progn
63 (newline 1)
64 (indent-to (1+ cc))
65 (insert (format
66 (if YaTeX-japan
67 "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境"
68 "%% TYPE undo(%s) to ACTIVATE caption. Twice to clear caption. 3 to no-env")
69 (key-description
70 (car (where-is-internal 'undo)))))
71 (put 'YaTeX-dnd-auto-figure 'guide t)))))
72 (YaTeX-help "includegraphics")
73 )
74 (set-marker envstart nil) ;;sure to reset marker
75 action))
76 ((string-match "\\.tex$" path)
77 (insert "\\include{" path "}"))
78 ))
79 (t (message "%s" action)))))
81 (provide 'yatex23)
83 ; Local variables:
84 ; fill-prefix: ";;; "
85 ; paragraph-start: "^$\\| \\|;;;$"
86 ; paragraph-separate: "^$\\| \\|;;;$"
87 ; coding: sjis
88 ; End: