yatex

view yatex23.el @ 402:27d24ac018c1

Explicitly feed second arg `t' to dnd-get-local-file-name. This enables emacs-22 to handle drag&drop images.
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 18 Jan 2015 22:08:31 +0900
parents e95ae850eefb
children 5b49aea3810d
line source
1 ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*-
2 ;;; (c)2014-2015 by HIROSE Yuuji.[yuuji@yatex.org]
3 ;;; Last modified Sun Jan 18 21:12:27 2015 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 (defvar YaTeX-dnd-auto-figure-package
11 (cons "graphicx"
12 (cond ((string-match "pdflatex" tex-command) "pdftex")
13 (t "dvipdfmx")))
14 "*Default LaTeX package and its option for \\includegraphics")
16 (defun YaTeX-dnd-handler (uri action)
17 "DnD handler for yatex-mode
18 Convert local image URI to \\includegraphcis{} and
19 .tex file names to \\include{}."
20 (let*((file (dnd-get-local-file-name uri t))
21 (path (save-excursion
22 (YaTeX-visit-main t)
23 (file-relative-name file)))
24 (insert-file-directory nil)
25 (case-fold-search t)
26 (b nil) p1 p2 (cc (current-column)) envstart)
27 (cond
28 ((memq action '(copy link move private))
29 (cond
30 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path)
31 (if (and (stringp YaTeX-dnd-auto-figure)
32 (not (YaTeX-in-environment-p YaTeX-dnd-auto-figure))
33 (not (string-match "figure"
34 (or (YaTeX-inner-environment t) "body")))
35 YaTeX-dnd-auto-figure)
36 (setq b (format "\\begin{%s}[htbp] %%\\centering\n"
37 YaTeX-dnd-auto-figure)))
38 (unwind-protect
39 (progn
40 (setq envstart (point-marker))
41 (insert "\\includegraphics")
42 (insert "{" (YaTeX::includegraphics 1 path t) "}")
43 (save-excursion
44 (YaTeX-package-auto-usepackage
45 "includegraphics" 'section
46 (car YaTeX-dnd-auto-figure-package)
47 (cdr YaTeX-dnd-auto-figure-package)))
48 (cond
49 (b
50 (undo-boundary)
51 (save-excursion
52 (goto-char envstart)
53 (insert b))
54 (YaTeX-indent-line)
55 (insert "\n")
56 (indent-to (1+ cc))
57 (setq p1 (point))
58 (insert "\\caption{")
59 (setq p2 (point))
60 (insert (format "}\\label{%s}\n" path))
61 (indent-to cc)
62 (insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure))
63 (goto-char p2)
64 (undo-boundary)
65 (insert (file-name-nondirectory path))
66 (undo-boundary)
67 (goto-char p1)
68 (insert "%")
69 (end-of-line)
70 (or (get 'YaTeX-dnd-auto-figure 'guide)
71 (progn
72 (newline 1)
73 (indent-to (1+ cc))
74 (insert (format
75 (if YaTeX-japan
76 "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境"
77 "%% TYPE undo(%s) to ACTIVATE caption. Twice to clear caption. 3 to no-env")
78 (key-description
79 (car (where-is-internal 'undo)))))
80 (put 'YaTeX-dnd-auto-figure 'guide t)))))
81 (YaTeX-help "includegraphics"))
82 (set-marker envstart nil) ;;sure to reset marker
83 action))
84 ((string-match "\\(.*\\)\\.tex$" path)
85 (insert "\\include{" (match-string 1 path) "}"))
86 ((string-match "\\(.*\\)\\.bib$" path)
87 (insert "\\bibliography{" (match-string 1 path) "}"))
88 ((string-match "\\.ind$" path)
89 (insert "\\input{" path "}"))))
90 (t (message "%s" action)))))
92 (defvar YaTeX-on-the-fly-bg-face '("#f0f0c0" . "#706868")
93 "Background color of on-the-fly preview image activated environment.")
94 (defvar YaTeX-on-the-fly-overlay nil
95 "Overlay of on-the-fly preview image")
96 (defface YaTeX-on-the-fly-activated-face
97 (list
98 (list (list '(class color) '(min-colors 65536))
99 (list ':background
100 (if (eq YaTeX-background-mode 'light)
101 (car YaTeX-on-the-fly-bg-face)
102 (cdr YaTeX-on-the-fly-bg-face))))
103 (list t (list ':bold t)))
104 "Face of on-the-fly preview image mode")
106 (provide 'yatex23)
108 ; Local variables:
109 ; fill-prefix: ";;; "
110 ; paragraph-start: "^$\\| \\|;;;$"
111 ; paragraph-separate: "^$\\| \\|;;;$"
112 ; coding: sjis
113 ; End: