[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 4f56ca6376: Add new user option `mouse-drag-mode-line-buffer'
From: |
Po Lu |
Subject: |
master 4f56ca6376: Add new user option `mouse-drag-mode-line-buffer' |
Date: |
Fri, 3 Jun 2022 03:22:05 -0400 (EDT) |
branch: master
commit 4f56ca63761b0270edb58734ce7ac4a3c800bb1b
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Add new user option `mouse-drag-mode-line-buffer'
* etc/NEWS: Announce new option. Also add missing entries for
an earlier change.
* lisp/mouse.el (mouse-drag-mode-line-buffer): New user option.
(mouse-drag-mode-line): Implement that option.
---
etc/NEWS | 10 +++++++---
lisp/mouse.el | 30 +++++++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 3870e937df..f9409bb24f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -305,6 +305,10 @@ the current Emacs process at the end, it starts a new
Emacs process
optional parameters to restart instead of just killing the current
process.
+** New user option 'mouse-drag-mode-line-buffer'.
+If non-nil, dragging on the buffer name part of the mode-line will
+drag the buffer's associated file to other programs.
+
+++
** New user option 'mouse-drag-and-drop-region-cross-program'.
If non-nil, this option allows dragging text in the region from Emacs
@@ -2083,9 +2087,9 @@ list in reported motion events if there is no frame
underneath the
mouse pointer.
+++
-** New function 'x-begin-drag'.
-This function initiates a drag-and-drop request with the contents of
-the selection 'XdndSelection', and returns when a drop occurs.
+** New functions 'x-begin-drag', 'dnd-begin-text-drag' and
'dnd-begin-file-drag'.
+These functions allow dragging contents (such as files and text) from
+Emacs to other programs.
---
** New function 'ietf-drums-parse-date-string'.
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 5834d4a666..1f2e925222 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -108,6 +108,13 @@ down and up respectively."
(integer :tag "This many lines from window top or bottom"))
:version "29.1")
+(defcustom mouse-drag-mode-line-buffer nil
+ "If non-nil, allow dragging files from the mode line.
+When the buffer has an associated file, it can be dragged from
+the buffer name portion of its mode line to other programs."
+ :type 'boolean
+ :version "29.1")
+
(defvar mouse--last-down nil)
(defun mouse--down-1-maybe-follows-link (&optional _prompt)
@@ -854,8 +861,29 @@ frame instead."
(interactive "e")
(let* ((start (event-start start-event))
(window (posn-window start))
- (frame (window-frame window)))
+ (frame (window-frame window))
+ (skip-tracking nil)
+ filename)
+ ;; FIXME: is there a better way of determining if the event
+ ;; started on a buffer name?
+ (when (and mouse-drag-mode-line-buffer
+ (eq (car (posn-string start))
+ (car (with-selected-window window
+ (setq filename (buffer-file-name))
+ mode-line-buffer-identification)))
+ filename
+ (file-exists-p filename))
+ (let ((mouse-fine-grained-tracking nil))
+ (track-mouse
+ (setq track-mouse 'drag-source)
+ (let ((event (read-event)))
+ (if (not (eq (event-basic-type event)
+ 'mouse-movement))
+ (push event unread-command-events)
+ (dnd-begin-file-drag filename frame 'copy t)
+ (setq skip-tracking t))))))
(cond
+ (skip-tracking t)
((not (window-live-p window)))
((or (not (window-at-side-p window 'bottom))
;; Allow resizing the minibuffer window if it's on the
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 4f56ca6376: Add new user option `mouse-drag-mode-line-buffer',
Po Lu <=