"Keymap used when point is over the link")
-(defun link-set-parent-keymap (keymap)
- "Defines `keymap' as parent keymap in the current buffer"
- ;; Force link-keymap to be local
- (unless (local-variable-p 'link-keymap (current-buffer))
- (make-local-variable 'link-keymap))
- ;; Ensure that keymap is a parent keymap
- ;; XEmacs defines set-keymap-parents
- (if (fboundp 'set-keymap-parents)
- (let ((parents (keymap-parents link-keymap)))
- (unless (member keymap parents)
- (set-keymap-parents link-keymap (append parents (list keymap)))))
- ;; GNU Emacs knows about set-keymap-parent
- (set-keymap-parent link-keymap keymap)))
(defun link-create-link (start end face function &optional data)
"Create a link in the current buffer starting from `start' going to `end'.
The `face' is used for displaying, the `data' are stored together with the
link. Upon clicking the `function' is called with `data' as argument."
- (link-set-parent-keymap (current-local-map))
(let ((properties `(face ,face
(link-create-link start (point) face function data)))
+(defun link-selected ()
"Is called upon clicking or otherwise visiting the link."
(function (extent-property extent 'link-function))
(data (extent-property extent 'link-data)))
- (funcall function data))))
+ (funcall function data))))
-(defun link-mouse-click (event)
+(defun link-selected-all ()
+ "Called for meta clicking the link"
+(defun link-mouse-click (event &optional all)
"Is called upon clicking the link."
+(defun link-mouse-click-all (event)
+ "Is called upon meta clicking the link."
+ (mouse-set-point event)
"Return the position of the next link or nil if there is none"
+(defun link-remove-link ()
+ "Remove the link at the current position"
+ (let ((extent (extent-at (point) (current-buffer))))
+ (delete-extent extent))))
(setq link-keymap (make-sparse-keymap))
(define-key link-keymap [button2] 'link-mouse-click)
- (define-key link-keymap [return] 'link-selected))
+ (define-key link-keymap [(meta button2)] 'link-mouse-click-all)
+ (define-key link-keymap [return] 'link-selected)
+ (define-key link-keymap [(meta return)] 'link-selected-all))