[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] Drag and drop support
From: |
Dr. Ing. Dieter Jurzitza |
Subject: |
Re: [AUCTeX] Drag and drop support |
Date: |
Sat, 18 Dec 2010 20:21:57 +0100 |
User-agent: |
KMail/1.13.5 (Linux/2.6.34.7-0.5-default; KDE/4.5.4; i686; ; ) |
Hi Michal,
thanks for your reply. That indeed works as expected. Hence I created a patch
for tex.el - you might notice line shifts, fax-sort-aliasesfile is another
local extension, so the patch will not work "out of the box" but anyway:
*********************************************************************
--- tex.el.original 2010-12-17 20:18:42.463093105 +0100
+++ tex.el 2010-12-17 20:01:44.279083356 +0100
@@ -58,6 +58,11 @@
"Various AUCTeX settings."
:group 'AUCTeX)
+(defgroup AUCTeX-dnd nil
+ "A (La)TeX drag-and-drop mode."
+ :tag "AUCTeX"
+ :group 'AUCTeX)
+
;;; Site Customization
;;
;; The following variables are likely to need to be changed for your
@@ -5671,6 +5676,48 @@
(fax-sort-aliasesfile)
(save-buffer))
+(defcustom AUCTeX-dnd-format "\\includegraphics[scale=1.0,angle=0]{%s}"
+ "What to insert, when a file is dropped on Emacs window. %s is
+replaced by the actual file name. If the filename is located
+under the directory of .tex document, only the part of the name
+relative to that directory in used."
+ :type 'string
+ :group 'AUCTeX)
+
+
+(defun AUCTeX-dnd-includegraphics (uri action)
+ "Insert the text defined by `AUCTeX-dnd-format' when a file is
+dropped on Emacs window."
+ (let ((file (dnd-get-local-file-name uri t)))
+ (when (and file (file-regular-p file))
+ (let* ((curdir (file-name-directory buffer-file-name))
+ (path (if (string-match curdir file)
+ (replace-match "" t t file)
+ file)))
+ (insert (format AUCTeX-dnd-format path))))))
+
+(defcustom AUCTeX-dnd-protocol-alist
+ '(("^file:///" . AUCTeX-dnd-includegraphics)
+ ("^file://" . dnd-open-file)
+ ("^file:" . AUCTeX-dnd-includegraphics))
+ "The functions to call when a drop in `mml-mode' is made.
+See `dnd-protocol-alist' for more information. When nil, behave
+as in other buffers."
+ :type '(choice (repeat (cons (regexp) (function)))
+ (const :tag "Behave as in other buffers" nil))
+ :version "22.1" ;; Gnus 5.10.9
+ :group 'AUCTeX)
+
+
+(define-minor-mode AUCTeX-dnd-mode
+ "Minor mode to inser some text (\includegraphics by default)
+when a file is dopped on Emacs window."
+ :lighter " DND"
+ (when (boundp 'dnd-protocol-alist)
+ (if AUCTeX-dnd-mode
+ (set (make-local-variable 'dnd-protocol-alist)
+ (append AUCTeX-dnd-protocol-alist dnd-protocol-alist))
+ (kill-local-variable 'dnd-protocol-alist))))
;; local additions done
;; Some versions of ispell 3 use this.
*********************************************************************
As suggested, I added the line
(add-hook 'LaTeX-mode-hook 'auctex-dnd-mode)
and things are working by default now - perfect. Moreove, configuration of
dnd-mode occurs now within the Auctex-group in the emacs-configuration dialog
- just as expected.
Nice thing, I really like it - thank you!
Take care
Dieter
Am Freitag, 17. Dezember 2010, 18:09:51 schrieb Michal Sojka:
**********
> As I wrote earlier, this was only a quick hack so I didn't polish the
> code. In any way, I'm glad that you like it.
>
> Cheers,
> Michal
**********
--
-----------------------------------------------------------
|
\
/\_/\ |
| ~x~ |/-----\ /
\ /- \_/
^^__ _ / _ ____ /
<°°__ \- \_/ | |/ | |
|| || _| _| _| _|
if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------