Summary: Mention mark-tools and helm
> == Mark Tools ==
> mark-tools.el provides a simple table for browsing the global and local mark-rings. The code is at: https://github.com/stsquad/emacs-mark-tools and the package is available on the MELPA and Marmalade repositories.
> == Helm ==
> Helm has M-x helm-mark-ring
Here are some common commands for manipulating and using the mark, in particular, for selecting things.
‘C-SPC’ to set the mark, and
‘C-x C-x’ to go back. A nice but often unknown feature is using universal argument:
‘C-u C-SPC’. It’s an easy way to navigate back to your previous editing spots by jumping to the positions stored in the buffer’s local mark ring. Repeated calls will cycle through the ring of marks.
If you use TransientMarkMode and you want to set the mark but don’t want to subsequently see the region highlighting, you can use
‘C-SPC C-g’ to set the mark and then deactivate it. You can also use
‘C-SPC C-SPC’, which may be faster for most people to type.
Unfortunately, traversing the mark ring with
‘C-u C-SPC’ can make you lose your last point if it is different from the mark. This happens when you fail to set the mark with
‘C-SPC’ before hitting
There is no way to traverse the mark ring in reverse nor skip N entries in the ring with a numeric PrefixArgument.
In addition to the ordinary mark ring that belongs to each buffer, Emacs has a single global mark ring. It records a sequence of buffers in which you have recently set the mark, so you can go back to those buffers.
Setting the mark always makes an entry on the current buffer’s mark ring. If you have switched buffers since the previous mark setting, the new mark position makes an entry on the global mark ring also. The result is that the global mark ring records a sequence of buffers that you have been in, and, for each buffer, a place where you set the mark.
‘C-x C-SPC’ (
‘pop-global-mark’) jumps to the buffer and position of the latest entry in the global mark ring. It also rotates the ring, so that successive uses of
‘C-x C-SPC’ take you to earlier and earlier buffers.
Icicles provides two commands,
‘icicle-goto-global-marker’, that let you navigate among markers. The former uses buffer-local markers; the latter uses global markers. You can navigate among markers using completion, as well as by cycling.
The completion is based on the text of the line the mark is in (or “
<EMPTY LINE>” if the line is empty). IOW, in buffer
‘*Completions*’, you can “see” all of the marks that are in lines that match your minibuffer input. You can use normal prefix matching or regexp (e.g. substring) matching. When your input is empty, you see the lines of all marks as navigation candidates. Typing some text filters the list of candidates incrementally, so they always match your input.
These commands are multi-commands (see Icicles - Multi-Commands): You can use
‘C-mouse-2’ to move around among selected markers, before deciding on a final destination with
These two Icicles commands are in fact specific applications of the generic function (and command)
‘icicle-apply’. That is, they are defined by using
‘icicle-apply’ to apply a simple go-to function to mark-ring candidates.
‘icicle-apply’ lets you apply any function to association-list entries in a selective, interactive fashion. The alist keys are used as the completion candidates, and choosing a candidate applies the function to that alist entry (key + value).
When you use command
‘icicle-apply’ interactively, it prompts you for the names of 1) a variable that has an alist value and 2) a function - you can use completion for each name. In Emacs, there are many alist variables; by default, they constitute the completion candidates for #1.
See: Icicles - Tripping.
You can use library thing-cmds.el to quickly mark (select) various kinds of things. Use it, for example, to mark successive sexps, lines, paragraphs, or words. Additional types of things are available. Commands:
‘mark-thing’– Select successive things of a given type.
‘cycle-thing-region’– Select a thing near point. Repeat to change to a different type of thing.
‘thing-region’– Select a thing near point. You are prompted for the type of thing.
Vanilla Emacs command
‘mark-word’ operates on words by using
‘M-f’) from point and setting mark at the end of the word. Most other
‘mark-’-style commands move the point – including
There exists a
‘current-word’ function in EmacsLisp that finds the word (or symbol) at the point from its beginning to its end. Since
‘current-word’ returns a string, and does not return region markers, it’s difficult to translate its results. This code uses ThingAtPoint to find the current word. Use it by EvaluatingExpressions in Emacs or by adding it to your Emacs InitFile.
(defun my-mark-current-word (&optional arg allow-extend) "Put point at beginning of current word, set mark at end." (interactive "p\np") (setq arg (if arg arg 1)) (if (and allow-extend (or (and (eq last-command this-command) (mark t)) (region-active-p))) (set-mark (save-excursion (when (< (mark) (point)) (setq arg (- arg))) (goto-char (mark)) (forward-word arg) (point))) (let ((wbounds (bounds-of-thing-at-point 'word))) (unless (consp wbounds) (error "No word at point")) (if (>= arg 0) (goto-char (car wbounds)) (goto-char (cdr wbounds))) (push-mark (save-excursion (forward-word arg) (point))) (activate-mark))))
(autoload 'mark-thing "thing-cmds") (defun mark-a-word-or-thing (arg) "Select word on or before current point, and move point to beginning of word. With a prefix ARG, first prompts for type of things and select ARG things but you need to move the point to the beginnig of thing first. But if a thing has been selected, then extend the selection by one thing on the other side of the point. (So to select backwards, select to the right first.)" (interactive "P") (if (or arg mark-active) (call-interactively 'mark-thing) (skip-syntax-backward "w_") (mark-thing 'word)))
You might want to set the prefix arg to nil before calling
‘mark-thing’, in the case where a plain prefix arg is used (e.g.
‘C-u C-u’ etc.). I doubt you frequently want to mark 4 (or 16 etc.) sexps. IOW:
(defun mark-a-word-or-thing (arg) "..." (interactive "P") (cond ((or arg mark-active) (when (consp arg) (setq current-prefix-arg nil)) (call-interactively 'mark-thing)) (t (skip-syntax-backward "w_") (mark-thing 'word))))
Alternatively, you might want to introduce some other behavior for plain
My point is that the prefix arg is being used for two different purposes: (1) choosing thing instead of word and (2) choosing how many things. At first reading, I didn’t notice #2, so was surprised by an error when it tried to scan forward 4 things and couldn’t. – DrewAdams
I agree that it’s confusing and even wasting the prefix argument feature. Here is an expanded version, again, assuming CUA mode.
I also note that the previous version has a conceptual bug: (skip-syntax-backward “w_”) doesn’t do the exactly the same thing as (backward-word 1) with additional care at the beginning of word. (Example: try put the point at the end of “abc-def”) As a user would expect that mark-thing to treat things like forward-thing, this is what our newer version does. – MaverickWoo
(defun mark-a-word-or-thing (arg) "Move point to beginning of current word and mark to end of word. Dropping the mark before first invocation flips the direction to backward. With a universal argument, and optionally a numerical prefix, call `mark-thing' interactively as if calling mark-thing. Ex: C-u 7 M-x mark-a-word-or-thing is equivalent to C-u 7 M-x mark-thing With a numerical prefix, mark ARG things forward, with things defaulted to be words. Ex: C-7 M-x mark-a-word-or-thing means \"mark 7 words, starting from current\" Without any argument in the first invocation, any existing selection will be preserved and extended by words. The extend direction is the same as your marking movement, ie, \"from mark towards point\". However, point will be exchanged with the mark to allow for subsequent invocations. Subsequent invocations, now with some things marked, will continue to mark the same type of things in the same direction as previous. Tested with CUA-mode Posted on http://www.emacswiki.org/cgi-bin/wiki/MarkCommands on 2007-11-21." (interactive "P") (cond ;; C-u => ask type and mark one of those ((consp arg) (setq current-prefix-arg nil) (call-interactively 'mark-thing)) ;; C-u C-7 => ask type and mark 7, generally ARG, of those ((>= (length (this-command-keys-vector)) 3) (call-interactively 'mark-thing)) ;; 2nd invoke => continue to mark whatever we have been marking ((eq this-command last-command) (mark-thing mark-thing-type (* (prefix-numeric-value arg) (if (< (mark) (point)) -1 1)) t)) ;; below are all 1st invokes ;; 1st invoke w/ existing => extend by word in the "right" direction ((and mark-active (< (mark) (point))) ;forward (exchange-point-and-mark) (mark-thing 'word (prefix-numeric-value arg) nil)) ;; 1st invoke w/ existing => extend by word in the "right" direction ((and mark-active (> (mark) (point))) ;backward (exchange-point-and-mark) (mark-thing 'word (- (prefix-numeric-value arg)) nil)) ;; C-SPC (drop mark) + 1st invoke => mark one word BACKWARDS ((and mark-active (= (mark) (point))) (setq CUA-explicit-region-start nil) ;to cancel C-SPC in CUA (unless (looking-at "\\>") (forward-word 1)) (mark-thing 'word (- (prefix-numeric-value arg)) nil)) ;; 1st invoke (t (unless (looking-at "\\<") (backward-word 1)) (mark-thing 'word (prefix-numeric-value arg) nil))))
I don’t see any advantage of this over mark-thing or cycle-thing-region.
‘word’ is already the default thing type. And you can change that default by customizing option
‘thing-types’: whatever is first in that list is the default type. – DrewAdams
Try AutoMark if you are tired of setting the mark manually.
expandregion.el is a very useful tool for increasing the selected region by semantic units. Download it at: https://github.com/magnars/expand-region.el
mark-tools.el provides a simple table for browsing the global and local mark-rings. The code is at: https://github.com/stsquad/emacs-mark-tools and the package is available on the MELPA and Marmalade repositories.
Helm has M-x helm-mark-ring