0

I am working on Python files and jump to beginning section to fix some imports and come back to point I am working on.

I want to use Bookmark, when I make a change on beginning of the file and come-back to the latest line I am working on. I was using ctrl+u+space, but I need to press multiple times to get back to latest point.

For following condition if possible:

  • When I jump to beginning of the buffer, also automatically I want to add a bookmark to the latest line I am working on.
  • Afterwards I made some changes on the import section, I want to get back to the latest bookmark (which is the right before I jumped), with a keybinding without entering its name into Jump to bookmark:.

Setup:

(global-set-key "\C-x\ ,"  'beginning-of-buffer);

(defadvice bookmark-jump (after bookmark-jump activate)
  (let ((latest (bookmark-get-bookmark bookmark)))
    (setq bookmark-alist (delq latest bookmark-alist))
    (add-to-list 'bookmark-alist latest)))

Example:

1   | import hello
2   | import world
...
20  | import python
...
1000| line_I_am_working_on = 100

I am on line 1000. Than I pressed Ctrl+x+, to jump to beginning of the buffer. Than I go to line-20 by pressing line-down (Ctrl+p) and make a change. As final step I want to jump back to line 1000.

  • Instead of using bookmarks, you should use the basic mark mechanism: beginning-of-buffer which is bound to M-< pushes a mark with the current position - you can then get back to it with C-x C-x. – NickD Jun 19 at 17:50
  • C-x C-x gets back to the position but it also highlights it from beginning of the file to the position. Is it possible to disable highlighting when C-x C-x is pressed? – alper Jun 19 at 19:03
  • C-g will get rid of the highlighting. Or you can disable transient-mark-mode, although IMO it's far too useful to disable. I use C-g. – NickD Jun 19 at 19:52
  • Is it possible to do following: I can bind C-x C-x into C-x C-x and followed by (C-g or C-SPC C-SPC) – alper Jun 20 at 1:00
  • 1
    Just use C-u C-x C-x instead. – NickD Jun 20 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.