annotate yatex23.el @ 348:3478a327ae41 dev

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

yatex.org