annotate lisp/hm--html-menus/hm--html-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: hm--html-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 contains functions to insert links and other
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
24 ;;; HTML stuff with the mouse with drag and drop.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
25 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
26 ;;; For further descriptions look at the file
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
27 ;;; internal-drag-and-drop.el, which implements the basic (and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
28 ;;; more genreal functions) for the drag and drop interface.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
29 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
30 ;;; Installation:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
31 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
32 ;;; Put this file in your load path.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
33 ;;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
34
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
35 (require 'internal-drag-and-drop)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
36 (require 'cl)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
37
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
38 (defun hm--html-first-non-matching-position (string1 string2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
39 "Compares both strings and returns the first position, which is not equal."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
40 (let ((n 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
41 (max-n (min (length string1) (length string2)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
42 (continue t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
43 (while (and continue (< n max-n))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
44 (when (setq continue (= (aref string1 n) (aref string2 n)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
45 (setq n (1+ n))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
46 n))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
47
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
48 (defun hm--html-count-subdirs (directory)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
49 "Returns the number of subdirectories of DIRECTORY."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
50 (let ((n 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
51 (max-n (1- (length directory)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
52 (count 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
53 (while (< n max-n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
54 (when (= ?/ (aref directory n))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
55 (setq count (1+ count)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
56 (setq n (1+ n)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
57 (when (and (not (= 0 (length directory)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
58 (not (= ?/ (aref directory 0))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
59 (setq count (1+ count)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
60 count))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
61
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
62 (defun hm--html-return-n-backwards (n)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
63 "Returns a string with N ../"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
64 (cond ((= n 0) "")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
65 (t (concat "../" (hm--html-return-n-backwards (1- n))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
66
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
67 (defun* hm--html-file-relative-name (file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
68 &optional (directory default-directory))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
69 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
70 (let* ((pos (hm--html-first-non-matching-position file-name directory))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
71 (backwards (hm--html-count-subdirs (substring directory pos)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
72 (relative-name (concat (hm--html-return-n-backwards backwards)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
73 (substring file-name pos))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
74 (if (= 0 (length relative-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
75 "./"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
76 (if (= ?/ (aref relative-name 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
77 (if (= 1 (length relative-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
78 "./"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
79 (substring relative-name 1))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
80 relative-name))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
81
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
82 (defun hm--html-idd-add-include-image-from-dired-line (source destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
83 "Inserts an include image tag at the SOURCE.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
84 The name of the image is on a line in a dired buffer. It is specified by the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
85 destination."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
86 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
87 (if hm--html-idd-create-relative-links
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
88 (hm--html-add-image-top (hm--html-file-relative-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
89 (idd-get-dired-filename-from-line destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
90 (file-name-nondirectory
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
91 (idd-get-dired-filename-from-line destination)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
92 (hm--html-add-image-top (idd-get-dired-filename-from-line destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
93 (file-name-nondirectory
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
94 (idd-get-dired-filename-from-line destination)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
95
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
96 (defun hm--html-idd-add-link-to-region (link-object source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
97 "Inserts a link with the LINK-OBJECT in the SOURCE.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
98 It uses the region as the name of the link."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
99 (idd-set-region source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
100 (hm--html-add-normal-link-to-region link-object)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
101 )
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
102
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
103 (defun hm--html-idd-add-link (link-object source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
104 "Inserts a link with the LINK-OBJECT in the SOURCE."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
105 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
106 (hm--html-add-normal-link link-object))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
107
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
108 (defun hm--html-idd-add-link-to-point-or-region (link-object source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
109 "Inserts a link with the LINK-OBJECT in the SOURCE.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
110 It uses the region as the name of the link, if the region was active
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
111 in the SOURCE."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
112 (if (cdr (assoc ':region-active source))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
113 (hm--html-idd-add-link-to-region link-object source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
114 (hm--html-idd-add-link link-object source)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
115
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
116 (defun hm--html-idd-add-file-link-to-file-on-dired-line (source destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
117 "Inserts a file link in SOURCE to the file on the dired line of DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
118 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
119 (if hm--html-idd-create-relative-links
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
120 (hm--html-idd-add-link-to-point-or-region
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
121 (hm--html-file-relative-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
122 (idd-get-dired-filename-from-line destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
123 source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
124 (hm--html-idd-add-link-to-point-or-region
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
125 (concat "file://" (idd-get-dired-filename-from-line destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
126 source)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
127
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
128 (defun hm--html-idd-add-file-link-to-buffer (source destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
129 "Inserts a file link at SOURCE to the file of DESTINATION."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
130 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
131 (if hm--html-idd-create-relative-links
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
132 (hm--html-idd-add-link-to-point-or-region
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
133 (hm--html-file-relative-name (idd-get-local-filename destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
134 source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
135 (hm--html-idd-add-link-to-point-or-region
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
136 (concat "file://" (idd-get-local-filename destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
137 source)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
138
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
139 (defun hm--html-idd-add-file-link-to-directory-of-buffer (source
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
140 destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
141 "Inserts a file link at SOURCE to the directory of the DESTINATION buffer."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
142 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
143 (if hm--html-idd-create-relative-links
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
144 (hm--html-idd-add-link-to-point-or-region
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
145 (hm--html-file-relative-name (idd-get-directory-of-buffer destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
146 source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
147 (hm--html-idd-add-link-to-point-or-region
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
148 (concat "file://" (idd-get-directory-of-buffer destination))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
149 source)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
150
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
151 (defun hm--html-idd-add-html-link-to-w3-buffer (source destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
152 "Inserts a link at SOURCE to the w3 buffer specified by the DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
153 Note: Relative links are currently not supported for this function."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
154 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
155 (hm--html-idd-add-link-to-point-or-region (idd-get-buffer-url destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
156 source))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
157
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
158 (defun hm--html-idd-add-html-link-from-w3-buffer-point (source destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
159 "Inserts a link at SOURCE to a lin in the w3 buffer.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
160 The link in the w3-buffer is specified by the DESTINATION.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
161 Note: Relative links are currently not supported for this function."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
162 (idd-set-point source)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
163 (hm--html-idd-add-link-to-point-or-region (idd-get-url-at-point destination)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
164 source))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
165
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
166 ;;; Announce the feature hm--html-drag-and-drop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents:
diff changeset
167 (provide 'hm--html-drag-and-drop)