I am trying to write functions that move cursor diagonally, for example:
(defun leftUp ()
(backward-char)
(previous-line))
but it works only once. On next calls cursor just moves straight up.
Any advice?
previous-line always tries to place the cursor on the same column as the cursor movement originally started in. See the variable goal-column for more information.
Related
I am trying to test if a certain position of an Emacs window is visible thus is neither overlapped by another window nor somehow obscured by decoration facilities. To this end I set the mouse position to a certain point and then compare the set values to (mouse-position). However, I get somewhat different values.
How does the actual (mouse-position) differ from the set value?
(Provided that mouse is not moved by the user, indeed).
To test it quickly C-x C-e
(list (set-mouse-position (selected-frame) 4 4) (mouse-position))
As for pos-visible-in-window-p, this does not perform an actual test. To see this
(progn (sleep-for 5) (pos-visible-in-window-p 1))
with C-u C-x C-e and lower, hide the window. Alas, it still is true.
It would seem that pos-visible-in-window-p should do what you want.
Note that your expression moves the actual mouse pointer, i.e., it is visible to the user.
I am new to emacs and I am using evil mode.
When I scroll with j,k and I move out of the screen, emacs will readjust the current line under the cursor to the middle of the screen.
Where can I disable this feature?
By adding the following setting to the .emacs file (or similar user customization file -- e.g., init.el), the user can override the default setting that recenters point as it moves off the screen:
(setq scroll-conservatively 101)
The doc-string for scroll-conservatively, which is visible by typing M-x describe-variable RET scroll-conservatively RET reads as follows (at least in so far as a developer snapshot of Emacs Trunk goes, that is):
"If the value is greater than 100, redisplay will never recenter point, but will always scroll just enough text to bring point into view, even if you move far away. A value of zero means always recenter point if it moves off screen."
I am trying to get out of evil mode, but one thing that is causing problems is that the forward incremental search places my cursor at the end of the match instead of the beginning. I very rarely want to have my cursor in the middle of the match which results in unnecessary keypresses to reposition the cursor. Is there a way to make the forward incremental search place the cursor at the beginning of the match instead of the end?
You question is addressed specifically in the Position of the Cursor after Searching
section of the IncrementalSearch page on Emacs Wiki. In particular, it shows you how to use isearch-mode-end-hook to get the behavior you want.
I suppose you can use defadvice to isearch-exit.
(defadvice isearch-exit (after move-to-match-beginning activate)
(when (and isearch-forward isearch-success)
(goto-char (match-beginning 0))))
Is it possible to let Emacs have the cursor be moved off-screen, like most GUI text editors work? This is one of the biggest things that bothers me when I use Emacs over any GUI editor. When I scroll down, the cursor is "pushed forward" by the top of the buffer.
I had previously thought that this was completely impossible, because this is hard-wired into the architecture of Emacs, but then I saw multiple-cursors, which does exactly this for the secondary cursors (assuming you prevent the scrolling functions from acting on the secondary cursors). Is it maybe possible to use multiple-cursors to have the main cursor in some hidden buffer, and the effective cursor being what I actually edit with? Or maybe some other clever trick? Or maybe my Googling has failed me and this is really already possible without any magic?
There is a new package available on GNU ELPA called scroll-restore that attempts to remedy this problem. So far, I have encountered a few bugs, but the package seems to work as-advertised for the most part.
You can test it out by installing it with
M-x package-install RET scroll-restore RET
After the package is installed, you can enable the minor mode with
M-x scroll-restore-mode
Personally, I am binding it to the Scroll Lock key because it seems so incredibly apropos! This is what I am adding to my init file:
(require 'scroll-restore)
(scroll-restore-mode 1)
;; Allow scroll-restore to modify the cursor face
(setq scroll-restore-handle-cursor t)
;; Make the cursor invisible while POINT is off-screen
(setq scroll-restore-cursor-type nil)
;; Jump back to the original cursor position after scrolling
(setq scroll-restore-jump-back t)
;; Toggle scroll-restore-mode with the Scroll Lock key
(global-set-key (kbd "<Scroll_Lock>") 'scroll-restore-mode)
This is a direct copy of an answer posted here: https://emacs.stackexchange.com/a/2273/93
Strictly, speaking you can't move the cursor offscreen, because the underlying C code won't let you do it.
This said, I suspect that your problem can be fixed. Basically, there are 2 aspects:
you don't like the way things look when "the cursor is pushed forward". You could work around that by (temporarily) making the cursor invisible.
you want to "jump back" to the pre-scrolling position as soon as you issue a non-scrolling command. There's probably some package out there that does it for you, but you can do it yourself with some pre-command-hook hacking.
BTW, I'd welcome patches in Emacs which provide some of that functionality. I hate the "auto jump-back" behavior of other editors, but it would be good to record the "pre-scroll" position and then offer a way to jump back to it.
Judging by the context and description of your problem, it looks like you want to browse the buffer while preserving your place of editing. There are at least two tricks for that purpose: marks/registers and splitting in two windows.
https://stackoverflow.com/a/3777598/308668 describes the Emacs' registers that act like Vim's marks. You can check in your place in the file with keying C-x r SPC a (a being a letter of your choice) and you can always come back with C-x r j a.
Some sort of automation is achieved by an external script (goto-last-change.el), described here: https://superuser.com/a/184402/49046.
Alternatively, split the window in two with C-x 2. The newly split windows both show the same location and you can use the other to explore. C-x 0 closes a window when you're done.
Is there a way to change Emacs' behavior when closing parentheses/bracket?
Right now, the cursor will jump to the opening bracket for a few seconds and will jump back after a while or when I start typing. I find this jumping back and forth really annoying.
Is there a way, to either
change the color/shape of the cursor when it's just marking the opening bracket, or
prevent the jumping at all, and just change the color of the matching pair?
Try putting
(show-paren-mode 1)
(setq blink-matching-delay 0.3)
in your .emacs or .emacs.d/init.el.
This prevents the jumping and highlights the matching pair.