annotate lisp/hm--html-menus/internal-drag-and-drop.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents
children 8fc7fe29b841
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
1 ;;; $Id: internal-drag-and-drop.el,v 1.1.1.1 1996/12/18 03:46:48 steve Exp $
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
2 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1996 Heiko Muenkel
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
4 ;;; email: muenkel@tnt.uni-hannover.de
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
5 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
6 ;;; This program is free software; you can redistribute it and/or modify
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
7 ;;; it under the terms of the GNU General Public License as published by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
8 ;;; the Free Software Foundation; either version 1, or (at your option)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
9 ;;; any later version.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
10 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
11 ;;; This program is distributed in the hope that it will be useful,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
14 ;;; GNU General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
15 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
16 ;;; You should have received a copy of the GNU General Public License
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
17 ;;; along with this program; if not, write to the Free Software
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
19 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
20 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
21 ;;; Description:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
22 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
23 ;;; This package provides functions to define and call internal
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
24 ;;; drag and drop actions in the emacs. One could start such an
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
25 ;;; action by clicking with the mouse in the source buffer and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26 ;;; then in the destination buffer. The action could depend on
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27 ;;; the points where youve clicked with the mouse, on the state
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28 ;;; of the region, the point, the mark and any other properties
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29 ;;; of the source and the destination buffers. The actions are
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30 ;;; defined by the variable `idd-actions', which is a buffer local
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31 ;;; variable. The following is an example for the html-mode:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32 ;;; (defvar html-idd-actions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 ;;; '((nil (((idd-major-mode-p . dired-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34 ;;; (idd-dired-file-on-line-p . ".*\\.\\(gif\\)\\|\\(jpq\\)"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 ;;; hm--html-idd-add-include-image-from-dired-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36 ;;; (((idd-major-mode-p . dired-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37 ;;; (idd-dired-no-file-on-line-p . nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 ;;; hm--html-idd-add-file-link-to-file-on-dired-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 ;;; (((idd-major-mode-p . dired-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
40 ;;; (idd-dired-no-file-on-line-p . t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 ;;; hm--html-idd-add-file-link-to-directory-of-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42 ;;; (((idd-major-mode-p . w3-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 ;;; (idd-url-at-point-p . t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 ;;; hm--html-idd-add-html-link-from-w3-buffer-point)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 ;;; (((idd-major-mode-p . w3-mode))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46 ;;; hm--html-idd-add-html-link-to-w3-buffer)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47 ;;; (((idd-local-file-p . t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 ;;; hm--html-idd-add-file-link-to-buffer)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49 ;;; Look at the variable `idd-actions' for further descriptions.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53 ;;; Installation:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 ;;; Put this file in one of your load path directories.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
56 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
57 ;;; Put the following in your .emacs:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
58 ;;; (autoload 'idd-mouse-drag-and-drop "internal-drag-and-drop"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
59 ;;; "Performs a drag and drop action.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
60 ;;; At first you must click on the source and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
61 ;;; after that on the destination."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
62 ;;; t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
63 ;;; (define-key global-map [(meta button1)] 'idd-mouse-drag-and-drop)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
64 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
65 ;;; Define actions in the variable `idd-actions'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
66 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
67
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
68 (defvar idd-actions nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
69 "The list with actions, depending on the source and the destination.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
70 The list looks like:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
71 '((<source-specification-1> (<destination-specification-1> <action-1-1>)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
72 (<destination-specification-2> <action-1-2>)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
73 :
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
74 )
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
75 (<source-specification-2> (<destination-specification-1> <action-2-1>)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
76 (<destination-specification-2> <action-2-2>)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
77 :
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
78 )
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
79 :
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
80 )
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
81 The <source-specification> looks like the following:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
82 '([(<specification-type> <value>)])
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
83 with <specification-type> :== idd-minor-mode-p | idd-buffer-name-p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
84 | idd-region-active-p ...
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
85
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
86 The <destination-specification> looks like <source-specification>, except
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
87 that a valid <specification-type> is also idd-major-mode-p.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
88
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
89 If <source-specification-1> or <destination-specification-1> is set to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
90 nil, then every source or destination matches. `idd-actions' is a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
91 buffer local variable, which should be at least mode depended. So if
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
92 the <source-specification-1> is set to nil it says, that the source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
93 buffer must only have a specific mode. But however, it's also possible
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
94 to define a general `idd-actions' list, where the source mode is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
95 specified by idd-major-mode-p.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
96
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
97 <action> ist a function, which has two arguments, the specifies the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
98 source and the second the destination.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
99
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
100 (make-variable-buffer-local 'idd-actions)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
101
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
102 (defun idd-compare-a-specification (source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
103 specification)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
104 "Tests if SOURCE-OR-DESTINATION matches the SPECIFICATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
105 It returns a value (1 in general) if both are matching or nil."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
106 (eval (list (car specification)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
107 'source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
108 '(cdr specification))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
109
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
110 (defun idd-compare-specifications-1 (source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
111 specifications
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
112 value)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
113 "Internal function of `idd-compare-specifications'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
114 VALUE is the value of the last matches."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
115 (cond ((not specifications) value)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
116 (t (let ((match (idd-compare-a-specification source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
117 (car specifications))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
118 (cond ((not match) 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
119 (t (idd-compare-specifications-1 source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
120 (cdr specifications)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
121 (+ value match))))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
122
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
123 (defun idd-compare-specifications (source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
124 specifications)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
125 "Determines how good SOURCE-OR-DESTINATION and SPECIFICATIONS are matching.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
126 A return value of zero means, that they don't match. The higher the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
127 return value the better is the matching."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
128 (cond ((not specifications) 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
129 (t (idd-compare-specifications-1 source-or-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
130 specifications
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
131 0))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
132
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
133 (defun idd-get-action-depending-on-destination (destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
134 actions-depending-on-dest
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
135 source-value
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
136 value-action-pair)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
137 "Internal function of `idd-get-action-depending-on-source-and-destination'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
138 (let ((destination-value (idd-compare-specifications
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
139 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
140 (car (car actions-depending-on-dest)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
141 (cond ((not actions-depending-on-dest) value-action-pair)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
142 ((or (= destination-value 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
143 (<= (+ source-value destination-value) (car value-action-pair)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
144 (idd-get-action-depending-on-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
145 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
146 (cdr actions-depending-on-dest)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
147 source-value
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
148 value-action-pair))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
149 (t (idd-get-action-depending-on-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
150 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
151 (cdr actions-depending-on-dest)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
152 source-value
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
153 (cons (+ source-value destination-value)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
154 (second (car actions-depending-on-dest))))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
155
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
156 (defun idd-get-action-depending-on-source-and-destination (source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
157 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
158 actions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
159 value-action-pair)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
160 "Internal function of `idd-get-action'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
161 VALUE-ACTION-PAIR is a list like (<value> <action>).
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
162 It returns VALUE-ACTION-PAIR, if no other action is found, which has a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
163 value higher than (car VALUE-ACTION-PAIR)."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
164 (let ((source-value (idd-compare-specifications source (car (car actions)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
165 (cond ((not actions) value-action-pair)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
166 ((= source-value 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
167 (idd-get-action-depending-on-source-and-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
168 source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
169 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
170 (cdr actions)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
171 value-action-pair))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
172 (t (idd-get-action-depending-on-source-and-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
173 source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
174 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
175 (cdr actions)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
176 (idd-get-action-depending-on-destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
177 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
178 (cdr (car actions))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
179 source-value
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
180 value-action-pair))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
181
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
182 (defun idd-get-action (source destination actions)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
183 "Returns the action, which depends on the SOURCE and the DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
184 The list ACTIONS contains all possible actions. Look at the variable
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
185 `idd-actions' for a description of the format of this list."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
186 (idd-get-action-depending-on-source-and-destination source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
187 destination
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
188 actions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
189 '(0 . nil)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
190
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
191 (defun idd-get-buffer-url (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
192 "Returns the URL of the buffer specified by SOURCE-OR-DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
193 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
194 (idd-set-point source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
195 (url-view-url t)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
196
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
197 (defun idd-get-url-at-point (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
198 "Returns the URL at the point specified by SOURCE-OR-DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
199 It returns nil, if there is no URL."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
200 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
201 (idd-set-point source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
202 (w3-view-this-url t)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
203
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
204 (defun idd-url-at-point-p (source-or-destination value)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
205 "Checks if there is an URL at the point of SOURCE-OR-DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
206 If that is t and VALUE is t, or that is nil and VALUE is nil, then 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
207 is returned. Otherwise nil is returned."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
208 (if value
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
209 (if (idd-get-url-at-point source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
210 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
211 nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
212 (if (idd-get-url-at-point source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
213 nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
214 1)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
215
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
216 (defun idd-major-mode-p (source-or-destination mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
217 "Checks, if the major mode of SOURCE-OR-DESTINATION is MODE.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
218 It returns 1, if that is t and nil otherwise."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
219 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
220 (set-buffer (cdr (assoc ':buffer source-or-destination)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
221 (if (eq major-mode mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
222 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
223 nil)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
224
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
225 (defun idd-set-point (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
226 "Sets the point and buffer to SOURCE-OR-DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
227 (set-buffer (cdr (assoc ':buffer source-or-destination)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
228 (goto-char (cdr (assoc ':drag-or-drop-point source-or-destination))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
229
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
230 (defun idd-set-region (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
231 "Sets the point, mark and buffer to SOURCE-OR-DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
232 The region is active after this function is called."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
233 (set-buffer (cdr (assoc ':buffer source-or-destination)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
234 (goto-char (car (cdr (assoc ':region-active source-or-destination))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
235 (set-mark (cdr (cdr (assoc ':region-active source-or-destination))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
236 (activate-region))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
237
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
238 (defun idd-get-dired-filename-from-line (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
239 "Returns the filename form the line in a dired buffer.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
240 The position and the buffer is specified by SOURCE-OR-DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
241 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
242 (idd-set-point source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
243 (dired-get-filename nil t)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
244
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
245 (defun idd-dired-file-on-line-p (source-or-destination filename-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
246 "Checks, if the filename on the line match FILENAME-REGEXP.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
247 The function `dired-get-filename' is used, to get the filename from
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
248 the SOURCE-OR-DESTINATION. It returns 1, if it matchs or nil."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
249 (let ((case-fold-search t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
250 (if (and (idd-get-dired-filename-from-line source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
251 (string-match filename-regexp
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
252 (idd-get-dired-filename-from-line
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
253 source-or-destination)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
254 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
255 nil)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
256
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
257 (defun idd-dired-no-file-on-line-p (source-or-destination value)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
258 "Checks, if a filename is in the dired buffer of SOURCE-OR-DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
259 It returns 1, if a filename is on the line and if VALUE is t, or if
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
260 no filename is on the line and VALUE is nil, otherwise it returns
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
261 nil. For the test the function `dired-get-filename' is used."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
262 (if (idd-get-dired-filename-from-line source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
263 (if value nil 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
264 (if value 1 nil)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
265
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
266 (autoload 'ange-ftp-ftp-path "ange-ftp"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
267 "Parse PATH according to ange-ftp-path-format (which see).
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
268 Returns a list (HOST USER PATH), or nil if PATH does not match the format.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
269
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
270 (defun idd-get-local-filename (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
271 "Returns the filename of a local file specified by SOURCE-OR-DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
272 (buffer-file-name (cdr (assoc ':buffer source-or-destination))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
273
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
274 (defun idd-get-directory-of-buffer (source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
275 "Returns the directory name assigned to the SOURCE-OR-DESTINATION buffer."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
276 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
277 (idd-set-point source-or-destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
278 default-directory))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
279
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
280 (defun idd-local-file-p (source-or-destination value)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
281 "Checks, if SOURCE-OR-DESTINATION has a file on the local filesystem.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
282 If that is t and VALUE is t, or that is nil and VALUE is nil, then 1
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
283 is returned. Otherwise nil is returned."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
284 (let ((filename (idd-get-local-filename source-or-destination)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
285 (if (and filename
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
286 (not (ange-ftp-ftp-path filename)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
287 (if value 1 nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
288 (if value nil 1))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
289
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
290 (defun idd-call-action (action source destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
291 "Calls the drag and drop ACTION with its arguments SOURCE and DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
292 (if (> (car action) 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
293 (if (symbol-function (cdr action))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
294 (eval (list (cdr action) 'source 'destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
295 (error "Error: Action %s isn't a valid function!" (cdr action)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
296 (message "No valid action defined for this source and this destination!")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
297
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
298 (defun idd-mouse-drag-and-drop (source-event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
299 "Performs a drag and drop action.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
300 At first you must click on the source and after that on the destination."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
301 (interactive "@e")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
302 (let ((source (list (cons ':buffer (current-buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
303 (cons ':drag-or-drop-point
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
304 (event-closest-point source-event))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
305 (cons ':region-active (if (region-active-p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
306 (cons (point)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
307 (mark))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
308 (destination nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
309 (destination-event))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
310 (if (adapt-xemacsp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
311 (dispatch-event (next-command-event)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
312 (setq destination-event
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
313 (next-command-event nil "Drag&Drop: Click on the destination!"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
314 (cond ((button-press-event-p destination-event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
315 (setq destination (list (cons ':buffer
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
316 (event-buffer destination-event))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
317 (cons ':drag-or-drop-point
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
318 (event-closest-point
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
319 destination-event))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
320 (cons ':region-active nil)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
321 (if (adapt-emacs19p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
322 (while (not (button-release-event-p (next-command-event)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
323 (idd-call-action (idd-get-action source destination idd-actions)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
324 source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
325 destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
326 (t (setq action "Wrong event") nil))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
327
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
328
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
329 (provide 'internal-drag-and-drop)