Source

hm--html-menus / internal-drag-and-drop.el

Diff from to

internal-drag-and-drop.el

 ;; Description:
 
 ;;	This package provides functions to define and call internal
-;;	drag and drop actions in the emacs. One could start such an 
-;;	action by clicking with the mouse in the source buffer and 
+;;	drag and drop actions in the emacs. One could start such an
+;;	action by clicking with the mouse in the source buffer and
 ;;	then in the destination buffer. The action could depend on
 ;;	the points where you've clicked with the mouse, on the state
 ;;	of the region, the point, the mark and any other properties
 ;;	variable. The following is an example for the hm--html-mode:
 ;;	(defvar hm--html-idd-actions
 ;;	  '((nil (((idd-if-major-mode-p . dired-mode)
-;;		   (idd-if-dired-file-on-line-p 
+;;		   (idd-if-dired-file-on-line-p
 ;;				. ".*\\.\\(gif\\)\\|\\(jpq\\)"))
 ;;		  hm--html-idd-add-include-image-from-dired-line)
 ;;		 (((idd-if-major-mode-p . dired-mode)
 ;;	Look at the variable `idd-actions' for further descriptions.
 
 
-;; Installation: 
+;; Installation:
 
 ;;	Put this file in one of your load path directories.
 
 ;;	Put the following in your .emacs:
 ;;	(autoload 'idd-mouse-drag-and-drop "internal-drag-and-drop"
 ;;	   "Performs a drag and drop action.
-;;         At first you must click on the source and 
+;;         At first you must click on the source and
 ;;         after that on the destination."
 ;;	   t)
 
 
 (defgroup idd-drag-and-drop nil
   "This package provides functions to define and call internal
-drag and drop actions in the emacs. One could start such an 
-action by clicking with the mouse in the source buffer and 
+drag and drop actions in the emacs. One could start such an
+action by clicking with the mouse in the source buffer and
 then in the destination buffer. The action could depend on
 the points where you've clicked with the mouse, on the state
 of the region, the point, the mark and any other properties
 the button down over the source and hold it until the mouse pointer
 is over the destination.
 
-The disadvantage of the `press-button-during-move' type compared with 
-the `click' type is, that you can't select a destination region and 
+The disadvantage of the `press-button-during-move' type compared with
+the `click' type is, that you can't select a destination region and
 therefore a drag and drop action depending on a selected region can't
 be started with that type of mouse binding.
 
   "The mouse keys for the command `idd-mouse-drag-and-drop'.
 The command `idd-mouse-drag-and-drop' is bound during the loading
 of the package internal-drag-and-drop to this keys in the global
-key map. 
+key map.
 
 Set it to nil, if you don't want to bind this function during loading.
 
 then this key sequence will not be bind.
 
 Note: In the Emacs 19 the mouse keys must contain the modifier
-`down', if `idd-drag-and-drop-mouse-binding-type' is set to 
+`down', if `idd-drag-and-drop-mouse-binding-type' is set to
 `press-button-during-move' and must not contain the modifier, if it
 is set to `click'. If you set `idd-drag-and-drop-mouse-binding-type'
 before loading the package internal-drag-and-drop, the mouse will
   "The mouse keys for the command `idd-help-mouse-drag-and-drop'.
 The command `idd-help-mouse-drag-and-drop' is bound during the loading
 of the package internal-drag-and-drop to this keys in the global
-key map. 
+key map.
 
 Set it to nil, if you don't want to bind this function during loading.
 
 then this key sequence will not be bind.
 
 Note: In the Emacs 19 the mouse keys must contain the modifier
-`down', if `idd-drag-and-drop-mouse-binding-type' is set to 
+`down', if `idd-drag-and-drop-mouse-binding-type' is set to
 `press-button-during-move' and must not contain the modifier, if it
 is set to `click'. If you set `idd-drag-and-drop-mouse-binding-type'
 before loading the package internal-drag-and-drop, the mouse will
 (defcustom idd-actions '((((idd-if-region-active-p . nil))
 			  (((idd-if-region-active-p . t))
 			   idd-action-copy-region))
-			 
+
 			 (((idd-if-region-active-p . t))
 			  (((idd-if-region-active-p . t))
 			   idd-action-copy-replace-region))
-			 
+
 			 (((idd-if-region-active-p . nil)
 			   (idd-if-modifiers-p . nil))
 			  (((idd-if-region-active-p . t))
 			   idd-action-move-region))
-			 
+
 			 (((idd-if-region-active-p . t)
 			   (idd-if-modifiers-p . nil))
 			  (((idd-if-region-active-p . t))
   "*The list with actions, depending on the source and the destination.
 The list looks like:
   '((<destination-specification-1> (<source-specification-1> <action-1-1>)
-                                   (<source-specification-2> <action-1-2>)
-                                   :
+				   (<source-specification-2> <action-1-2>)
+				   :
      )
     (<destination-specification-2> (<source-specification-1> <action-2-1>)
-                                   (<source-specification-2> <action-2-2>)
-                                    :
+				   (<source-specification-2> <action-2-2>)
+				    :
      )
     :
     )
   '([(<specification-type> <value>)])
 with <specification-type> :== idd-if-minor-mode-p | idd-if-buffer-name-p
 			      | idd-if-region-active-p | idd-if-url-at-point-p
-                              | idd-if-major-mode-p | idd-if-variable-non-nil-p
-                              | idd-if-dired-file-on-line-p
-                              | idd-if-dired-no-file-on-line-p
-                              | idd-if-local-file-p | idd-if-buffer-name-p
-                              | idd-if-modifiers-p | ...
+			      | idd-if-major-mode-p | idd-if-variable-non-nil-p
+			      | idd-if-dired-file-on-line-p
+			      | idd-if-dired-no-file-on-line-p
+			      | idd-if-local-file-p | idd-if-buffer-name-p
+			      | idd-if-modifiers-p | ...
 
 The <specification-type> - functions must have two arguments, the first one
 is the source or destination and the second is the <value>. It must return
-nil, if the test wasn't successful and a number (in general 1), which 
+nil, if the test wasn't successful and a number (in general 1), which
 specifies the weight of the test function. The weights of all single tests
 are added to a summary weight and assigned to the action. The action
 with the highest weight is called from the action handler. Look at
 
 <action> is a function, which has two arguments, the first specifies the
 source and the second the destination. Look at the function definition
-of `idd-action-copy-region' and `idd-action-copy-replace-region'. They are 
+of `idd-action-copy-region' and `idd-action-copy-replace-region'. They are
 examples for such actions."
   :group 'idd-drag-and-drop
-  :type 'list)
+  :type 'sexp)
 
 (make-variable-buffer-local 'idd-actions)
 
   :group 'idd-drag-and-drop
   :type 'file)
 
-(defcustom idd-data-directory (or 
+(defcustom idd-data-directory (or
 			       (and (fboundp 'locate-data-directory)
 				    (locate-data-directory "hm--html-menus"))
-			       (file-name-as-directory 
+			       (file-name-as-directory
 				(expand-file-name "idd" data-directory)))
   "Data directory for the file `idd-mouse-pointer-image'.
 Run the command `idd-make-drag-and-drop-pointer-glyph' after changing
   :group 'idd-drag-and-drop
   :type 'directory)
 
-(defcustom idd-overwrite-mouse-pointers 
-  (if (adapt-xemacsp) 
+(defcustom idd-overwrite-mouse-pointers
+  (if (adapt-xemacsp)
       '(text-pointer-glyph
 	nontext-pointer-glyph
 	selection-pointer-glyph)
 
 (defvar idd-drag-and-drop-pointer-glyph nil
 ;  (if idd-overwrite-mouse-pointers
-;      (make-pointer-glyph 
+;      (make-pointer-glyph
 ;       (vector 'autodetect :data idd-mouse-pointer-image))
 ;    nil)
   "The shape of the mouse-pointer when internal drag and drop is active.")
     (cond ((not actions-depending-on-source) value-action-pair)
 	  ((or (= source-value 0)
 	       (<= (+ destination-value source-value) (car value-action-pair)))
-	   (idd-get-action-depending-on-source 
+	   (idd-get-action-depending-on-source
 	    source
 	    (cdr actions-depending-on-source)
 	    destination-value
 	    value-action-pair))
-	  (t (idd-get-action-depending-on-source 
+	  (t (idd-get-action-depending-on-source
 	      source
 	      (cdr actions-depending-on-source)
 	      destination-value
 			    source-or-destination)))
 	1
       nil)))
-	       
+
 (defun idd-if-dired-no-file-on-line-p (source-or-destination value)
   "Checks, if a filename is in the dired buffer of SOURCE-OR-DESTINATION.
 It returns 1, if a filename is on the line and if VALUE is t, or if
        (idd-set-point ,destination))
      ,(when do-in-destination
 	(cons 'progn do-in-destination))))
-  
+
 (defun idd-action-move-region (source destination)
   "Move the region from SOURCE to DESTINATION."
   (let ((region))
-    (idd-with-source-and-destination 
+    (idd-with-source-and-destination
      source destination
      :do-in-source ((setq region (buffer-substring (point) (mark)))
 		    (delete-region (point) (mark)))
 (defun idd-action-move-replace-region (source destination)
   "Delete the region at SOURCE and overwrite the DESTINATION region with it."
   (let ((region))
-    (idd-with-source-and-destination 
+    (idd-with-source-and-destination
      source destination
      :do-in-source ((setq region (buffer-substring (point) (mark)))
 		    (delete-region (point) (mark)))
 		     (mouse-event-p source-event)
 		     (eq idd-drag-and-drop-mouse-binding-type 'click))
 	    (while (not (button-release-event-p (next-command-event)))))
-	  (idd-mouse-drag-and-drop source-event)) 
+	  (idd-mouse-drag-and-drop source-event))
       (message "Wrong event! Exit drag and drop."))))
 
 (defun idd-help-mouse-drag-and-drop (source-event)
 
 (defun idd-mouse-drag-and-drop (source-event)
   "Performs a drag and drop action.
-It calls the command `idd-mouse-drag-and-drop-click' or 
+It calls the command `idd-mouse-drag-and-drop-click' or
 `idd-mouse-drag-and-drop-press-button-during-move' depending on
 the value of `idd-drag-and-drop-mouse-binding-type'."
   (interactive "@e")
 At first you must press the button down over the source and then
 move with the pressed button to the destination, where you must leave
 the button up.
-This must be bind to a mouse button. The SOURCE-EVENT must be a 
+This must be bind to a mouse button. The SOURCE-EVENT must be a
 button-press-event.
 
 The disadvantage of this command compared with the command
 destination region."
   (interactive "@e")
   (idd-set-drag-and-drop-pointer-glyphs)
-  (let ((drag-and-drop-message 
+  (let ((drag-and-drop-message
 	 "Drag&Drop: Leave the button over the destination!")
 	(source (idd-get-source-or-destination-alist source-event))
 	(destination nil)
 	(destination-event))
     (message drag-and-drop-message)
-    (setq destination-event 
+    (setq destination-event
 	  (next-command-event nil drag-and-drop-message))
     (message "")
     (cond ((or (button-release-event-p destination-event)
 (defun idd-mouse-drag-and-drop-click (source-event)
   "Performs a drag and drop action.
 At first you must click on the source and after that on the destination.
-This must be bind to a mouse button. The SOURCE-EVENT must be a 
+This must be bind to a mouse button. The SOURCE-EVENT must be a
 button-press-event."
   (interactive "@e")
   (idd-set-drag-and-drop-pointer-glyphs)
     (message drag-and-drop-message)
     (when (and (adapt-xemacsp) (mouse-event-p source-event))
       (dispatch-event (next-command-event)))
-    (setq destination-event 
+    (setq destination-event
 	  (next-command-event nil drag-and-drop-message))
     (message "")
     (cond ((button-press-event-p destination-event)
 				     idd-mouse-pointer-image)))
 	  (if (and mouse-pointer-image
 		   (file-exists-p mouse-pointer-image))
-	      (setq idd-drag-and-drop-pointer-glyph 
-		    (make-pointer-glyph 
+	      (setq idd-drag-and-drop-pointer-glyph
+		    (make-pointer-glyph
 		     (vector 'autodetect :data mouse-pointer-image)))
 	    (setq idd-drag-and-drop-pointer-glyph (make-pointer-glyph))
-	    (message 
+	    (message
 	     "Warning: Can't find drag and drop mouse pointer image!"))))
-      
+
       (when (and (not noninteractive) (console-on-window-system-p))
 	(idd-make-drag-and-drop-pointer-glyph))
-      
+
       ))
 
 ;; keymap for help buffer extents