rejeep / drag-stuff.el Goto Github PK
View Code? Open in Web Editor NEWDrag stuff around in Emacs
Drag stuff around in Emacs
I upgraded from Emacs 24.3 to 26 and realized that drag-stuff no longer works. I tried various suggestion in #25 but none of them works.
Could a toggle be added for drag-stuff that handles both, turning it on and off?
Hi, I was using move-text and found this package recently.
Could you please describe the difference between drag-stuff and move-text?
Thanks!
... probably depending on the mode. E.g. if a sentence is selected in text mode, it makes sense to be able to move it to before the preceding, or to after the following, sentence.
This does blur the boundary between left/right and up/down. Related, but more like before/after.
Semantic units in the sense of https://github.com/magnars/expand-region.el
drag-stuff is brilliant :)
unfortunately for two cursors in two consequent lines (line n and n+1) it only works upwards (dragging towards bottom has no effect). It works with no hassle in both directions when the two cursors are separated with at least one line that has no cursor in it...
When I move selection UP/DOWN
It moves only line with cursor, but not all selected region.
If my cursor is on line 3 with 4 and 5 lines selected - it will move only 3rd line, but 2 linese above (whenever I will move 3rd line) will be selected.
I used
(drag-stuff-global-mode t) (setq drag-stuff-modifier '(control shift))
for setup
But when I enter C+S+up or C+S+down, it does not work.
Thank you very much!
Dear Mr Andersson,
thank you for sharing this useful package.
It seem to me that Drag Stuff Mode is not global, because I have added this lines to my .emacs
:
(require 'drag-stuff)
(drag-stuff-mode t)
But I still have to enable Drag Stuff Mode manually. Unless I am doing something wrong, would you please consider making Drag Stuff Mode a global minor mode?
Thanks for your attention.
Best Regards
I use drag-stuff-global-mode
, and I prefer keybindings that are different from the ones defined in drag-stuff-define-keys
.
If I use the local minor mode, I can customize drag-stuff-mode-map
in a straightforward way, but in the global minor mode, my keybindings refuse to take hold unless I wrap them in a defun and add the resulting function to drag-stuff-mode-hook
.
(defun ivan/bind-drag-stuff-keys ()
;; unset the defaults
(define-key drag-stuff-mode-map (drag-stuff--kbd 'up) nil)
(define-key drag-stuff-mode-map (drag-stuff--kbd 'down) nil)
(define-key drag-stuff-mode-map (drag-stuff--kbd 'right) nil)
(define-key drag-stuff-mode-map (drag-stuff--kbd 'left) nil)
;; apply my bindings
(define-key drag-stuff-mode-map (kbd "C-M-k") 'drag-stuff-up)
(define-key drag-stuff-mode-map (kbd "C-M-j") 'drag-stuff-down)
(define-key drag-stuff-mode-map (kbd "C-M-l") 'drag-stuff-right)
(define-key drag-stuff-mode-map (kbd "C-M-h") 'drag-stuff-left))
(add-hook 'drag-stuff-mode-hook
'ivan/bind-drag-stuff-keys)
(drag-stuff-global-mode t)
Without resorting to the above use of hooks, my custom bindings get clobbered by drag-stuff-define-keys
, though I don't yet understand why this is only an issue in the global mode.
I'm still learning elisp, but I'm under the impression that this workaround shouldn't be necessary. I've noticed that a lot of packages will provide a function like drag-stuff-define-keys
but leave it up to the user to actually call it, as this provides more flexibility.
The default 'meta works fine, so does setting 'control or 'shift. Setting 'super however binds the commands to shift+super. A bit unexpected. I'd like to be able to use 'super alone.
Several times I have found myself wanting the ability to drag a (mode-specific) defun up and down (swapping places with other defuns, not a line at a time). I don't have time to work on this right now, so I thought I would put it here in case someone else wants to implement it before I get around to it.
I think the hardest part will be the interface i.e. how to I indicate that I want to drag a defun instead of a region. It might also be nice to drag sexp's, though that is easier to deal with since there is transpose-sexps
.
Hi,
Thanks for coding this package. It's very helpful for moving lines or blocks of code.
I face only one issue when I am moving block of lines using region select.
Let's say the code has 3 lines. If I go to line 1, C-a, C-space, C-n, C-n, that will select lines 1 and 2. When I do drag-stuff-down
, I expect to drag only lines 1 and 2. But line 3 moves as well.
Can you please change the behavior so that only the selected region moves? Right now it looks like line 3 is being moved because after selecting lines 1 and 2, the cursor position is on line 3.
Hello,
When dragging stuff down with electric-indent-mode enabled, lines get too much indentation. for example.
before:
line
after dragging line down 3 times:
line
Thanks
looks like emacs 25 introduces a rectangular selection mode, but with drag-stuff it doesn't do quite what you would expect it to do which is move the whole blob around. any idea about how feasible it would be.
When I select few lines, it dragged together with adjacent bottom one.
Could you please tag a commit so that melpa stable gets updated? The version on melpa-stable is from 2014.
Since you're using Melpa, is it possible to auto install this package if we have melpa-stable
installed in our emacs.d/? Like :
(use-package drag-stuff)
(require 'drag-stuff)
Would that be enough?
(add-to-list 'load-path "/path/to/drag-stuff")
<- this is what I want to avoid doing since I would have to manually create a folder in my .emacs.d/
right?
EDIT :
I put this in my init.el and all went fine.
(use-package drag-stuff)
(require 'drag-stuff)
(drag-stuff-global-mode t)
(drag-stuff-define-keys)
I had a few warnings though :
Leaving directory ‘/home/manuel/.emacs.d/elpa/drag-stuff-20161108.749’
Compiling file /home/manuel/.emacs.d/elpa/drag-stuff-20161108.749/drag-stuff.el at Fri Feb 21 23:07:44 2020
Entering directory ‘/home/manuel/.emacs.d/elpa/drag-stuff-20161108.749/’
Warning (bytecomp): reference to free variable ‘evilp’
Warning (bytecomp): reference to free variable ‘evil-visual-mark’
Warning (bytecomp): reference to free variable ‘evilp’
Warning (bytecomp): reference to free variable ‘evil-visual-point’
Warning (bytecomp): reference to free variable ‘evilp’
Warning (bytecomp): reference to free variable ‘evil-visual-mark’
Warning (bytecomp): reference to free variable ‘evilp’
Warning (bytecomp): reference to free variable ‘evil-visual-point’
Warning (bytecomp): ‘goto-line’ is for interactive use only; use ‘forward-line’ instead.
Warning (bytecomp): reference to free variable ‘arg’
Warning (bytecomp): ‘goto-line’ is for interactive use only; use ‘forward-line’ instead.
Warning (bytecomp): reference to free variable ‘evilp’
Warning (bytecomp): the following functions are not known to be defined:
evil-visual-state-p, longlines-mode, evil-visual-goto-end,
evil-visual-type, evil-visual-make-selection, evil-visual-line,
evil-exit-visual-state
Example:
(
foobar
foo
;; baz
)
Try to drag foo
one line up. Result:
(
foo
foobar ;; baz
)
Note that this was in elisp mode, and the fact that ;; baz
started with a comment was necessary for the repro.
I put
(add-to-list 'load-path "~/")
(require 'drag-stuff)
in ~/.emacs
and drag-stuff.el in ~/
but cannot get installed and error message in emacs initialization
How to solve it ? Please give me guidance !
Any hope to get this working with visual line mode in evil-mode? If I select a few lines using visual line mode, and try to drag it, it seems to not recognize the selection, it does something weird, like transposing or something. Dragging single lines in normal mode works great, and if I select using C+Space in insert mode, and drag that works fine. (If I select using C+Space in insert mode, and go back to normal mode, it retains the selection -- this looks exactly the same as with visual line mode, but in this case, drag-stuff works perfectly with the whole region).
So the problem seems to be that a visual-line mode selection isn't recognized by drag stuff. This is weird, because other Emacs commands that are not related to evil-mode seem to recognize the region generated by visual line mode (for example, just to test - studlify-region).
I'd love to get this to work, and would be happy to help test, etc!
Running drag-stuff in emacs 28 with native compilation shows the following warnings:
Warning (comp): drag-stuff.el:69:13: Warning: Package cl is deprecated Disable showing Disable logging
Warning (comp): drag-stuff.el:106:8: Warning: reference to free variable `evilp' Disable showing Disable logging
Warning (comp): drag-stuff.el:106:14: Warning: reference to free variable `evil-visual-mark' Disable showing Disable logging
Warning (comp): drag-stuff.el:111:8: Warning: reference to free variable `evilp' Disable showing Disable logging
Warning (comp): drag-stuff.el:111:14: Warning: reference to free variable `evil-visual-point' Disable showing Disable logging
Warning (comp): drag-stuff.el:115:7: Warning: reference to free variable `evilp' Disable showing Disable logging
Warning (comp): drag-stuff.el:116:43: Warning: reference to free variable `evil-visual-mark' Disable showing Disable logging
Warning (comp): drag-stuff.el:121:7: Warning: reference to free variable `evilp' Disable showing Disable logging
Warning (comp): drag-stuff.el:122:43: Warning: reference to free variable `evil-visual-point' Disable showing Disable logging
Warning (comp): drag-stuff.el:230:14: Warning: `goto-line' is for interactive use only; use `forward-line' instead. Disable showing Disable logging
Warning (comp): drag-stuff.el:237:19: Warning: reference to free variable `arg' Disable showing Disable logging
Warning (comp): drag-stuff.el:235:6: Warning: `goto-line' is for interactive use only; use `forward-line' instead. Disable showing Disable logging
Warning (comp): drag-stuff.el:270:12: Warning: reference to free variable `evilp' Disable showing Disable logging
Warning (comp): drag-stuff.el:357:31: Warning: defcustom for `drag-stuff-global-mode' fails to specify containing group Disable showing Disable logging
Warning (comp): drag-stuff.el:357:31: Warning: defcustom for `drag-stuff-global-mode' fails to specify containing group Disable showing Disable logging
Warning (comp): drag-stuff.el:247:33: Warning: the function `evil-exit-visual-state' is not known to be defined. Disable showing Disable logging
Warning (comp): drag-stuff.el:241:31: Warning: the function `evil-visual-line' is not known to be defined. Disable showing Disable logging
Warning (comp): drag-stuff.el:240:8: Warning: the function `evil-visual-make-selection' is not known to be defined. Disable showing Disable logging
Warning (comp): drag-stuff.el:220:28: Warning: the function `evil-visual-type' is not known to be defined. Disable showing Disable logging
Warning (comp): drag-stuff.el:209:54: Warning: the function `evil-visual-goto-end' is not known to be defined. Disable showing Disable logging
Warning (comp): drag-stuff.el:142:4: Warning: the function `longlines-mode' is not known to be defined. Disable showing Disable logging
Warning (comp): drag-stuff.el:94:38: Warning: the function `evil-visual-state-p' is not known to be defined. Disable showing Disable logging
Unfortunately I completely fail to build and install drag-stuff using el-get. It's probably not an issue of el-get, bu provided just for information. It ends up with following trace:
Submodule 'util/ecukes' (git://github.com/rejeep/ecukes.git) registered for path 'util/ecukes'
Submodule 'util/espuds' (git://github.com/rejeep/espuds.git) registered for path 'util/espuds'
Cloning into util/ecukes...
Submodule path 'util/ecukes': checked out 'b778a1840e92993abf1d656f162aa1ab5cca930a'
Submodule 'test/el-mock' (git://github.com/emacsmirror/el-mock.git) registered for path 'test/el-mock'
Submodule 'test/ert' (git://github.com/nex3/ert.git) registered for path 'test/ert'
Cloning into test/el-mock...
fatal: reference is not a tree: 6039afd28dd3eea64014f364ac490fb7c6eb0108
Unable to checkout '6039afd28dd3eea64014f364ac490fb7c6eb0108' in submodule path 'test/el-mock'
Failed to recurse into submodule path 'util/ecukes'
I'm wondering if there is a way to drag things around with the mouse instead of the keyboard.
When you try to drag word when cursor at first char of a word, it drags the left neighbour word
illustration: (assuming bold face is the place where cursor is.
word1 word2 word3 word4
after M-<left>
word2 word1 word3 word4
vimish-fold sets read-only property to regions of text in buffer. Currently, when trying to drug stuff over read-only buffer part results in current line or selection (stuff being dragged) getting removed. It would be nice if code would handle this more gracefully - either jumping over readonly part or signalling error without removing text.
the interactive functions drag-stuff-up-down
and its three siblings are not marked as autoloadable. since i do not like the default key bindings (i do not use cursor keys at all) i want to bind my own custom keys, but right now this requires an explicit (require ...)
of this package to load the relevant functions.
hence my request: please mark those as autoloaded as well. thanks!
The up/down functionality is very useful, but M-left
/ M-right
are Readline / Emacs default binding, so the drag-left and drag-right on those bindings is extremely unwelcome.
I suggest they are re-bound to keep them out of default bindings.
Users can easily override Emacs defaults themselves if they want to use them in this way.
Hi rejeep,
thanks for your neat scripts, I use it everyday.
However, when i use it in org-mode, there is some kind of bother sometimes. Maybe you know that, I can use Alt left
and Alt right
to promote and demote the heading, or use Alt up
and Alt down
to move the headings. They are all conflicted with drag-stuff mode.
So I come here to require a feature that can inhibit the drag-stuff-mode temporarily when the cursor is in heading and subheading in org-mode, and I think it will be a good feature because we almost put our cursor in the contents but the headings.
Thanks in advance. Best regard.
llcc
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.