4

Is there any way to combine local and global marks together? what I am trying to do is just to have a common keybinding to pop-global-mark and set-mark-command. Something like; "try to pop the local mark, if there are no remaining ones, then try pop the global mark".

This is needed to move back around the code, and not thinking if i should press C-u C-SPC or C-x C-SPC, depending if the jump between functions was inside or outside the same file.

Borja Tarraso
  • 863
  • 2
  • 12
  • 20

2 Answers2

2

First of all, you cannot really use set-mark-command in code because it checks this-command and last-command so it will not work as intended.

However, examining its code, I came up with (untested!):

(defun pop-local-or-global-mark ()
  "Pop to local mark if it exists or to the global mark if it does not."
  (interactive)
  (if (mark t)
      (pop-to-mark-command)
      (pop-global-mark)))
sds
  • 58,617
  • 29
  • 161
  • 278
  • Well, I only saw one 'strange' behavior. Is when I go back from one file to another, it really does not jump to the line of caller function, it jumps to the previous mark from the same local file where it is the line of caller function. To reproduce this, I was jumping between functions in the same file, later I jump to function that was in another file, and then try to go back. – Borja Tarraso Dec 06 '13 at 19:30
2

I think you're perhaps under a misconception that C-u C-SPC and C-x C-SPC actually "pop" the mark rings, in the sense of shortening them. I say this because you write "if there are no remaining ones".

They do not. They cycle the mark rings. So continuing to pop the local mark ring will not eventually lead to it being empty, allowing your envisioned command to then move on to pop the global mark ring.

These two rings are separate primarily because they are used differently. The global ring gets you from buffer to buffer (only). The local rings move you around within individual buffers (only).

So my advice would be to not look for what you are looking for ;-). Or if you really want it, then define commands that actually do pop the rings, in the sense of removing markers.

FWIW, there are alternatives to these two commands, including commands that let you see the text associated with the markers and choose a destination using, e.g., completion.

In Icicles for instance, C-u C-SPC combines marker cycling with setting the mark, as your intro sentence requests (but not as your title requests -- there are separate Icicles commands for cycling the local and global rings). Similarly, C-x C-SPC does this for the global ring. In Icicle mode, by default, these keys are bound to multi-commands icicle-goto-marker-or-set-mark-command and icicle-goto-global-marker-or-pop-global-mark.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • Well, what i was looking for, it is to jump from function call to function call (even if the function was in the same file or across different files) and then return back in the same way but in opposite direction. BTW I am using semantic at the same time so I was using semantic-ia-fast-jump combining with set-mark-command passing as a parameter 4, to return back. But this last one only works within the same local file, is why I need to combine with pop-global-mark. So what I was trying to find is the analog function of semantic-ia-fast-jump. – Borja Tarraso Dec 06 '13 at 19:19
  • 1
    Sorry, I don't use Semantic, so I can't help you there. Hopefully someone else will. I will add, however, that you can also use [**Bookmark+**](http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus), including with [temporary bookmarks](http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus#toc56). Just hit a key to bookmark a position; no need to give a bookmark name. And you can optionally highlight the locations (e.g. a mark in the fringe). And you can [cycle](http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus#toc50) among sets of bookmarks. – Drew Dec 06 '13 at 19:33