Mercurial > hgrepos > hgweb.cgi > yatex
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 |
rev | line source |
---|---|
330 | 1 ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*- |
2 ;;; (c)2014 by HIROSE Yuuji.[yuuji@yatex.org] | |
348 | 3 ;;; Last modified Fri Dec 19 21:43:54 2014 on firestorm |
330 | 4 ;;; $Id:$ |
5 | |
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 | 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{}." | |
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 | 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 | 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 | 76 (insert "\\include{" (match-string 1 path) "}")) |
77 ((string-match "\\(.*\\)\\.bib$" path) | |
78 (insert "\\bibliography{" (match-string 1 path) "}")) | |
79 ((string-match "\\.ind$" path) | |
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 | 82 |
83 (provide 'yatex23) | |
84 | |
85 ; Local variables: | |
86 ; fill-prefix: ";;; " | |
87 ; paragraph-start: "^$\\|\\|;;;$" | |
88 ; paragraph-separate: "^$\\|\\|;;;$" | |
89 ; coding: sjis | |
90 ; End: |