Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not hard to find something around point in elisp. Just use two searches, forward and backward.</p> <pre><code>(defun set-selection-around-parens() (interactive) (let ( (right-paren (save-excursion ; using save-excursion because ; we don't want to move the ; point. (re-search-forward ")" nil t))) ; bound nil ; no-error t (left-paren (save-excursion (re-search-backward "(" nil t)))) (when (and right-paren left-paren) ;; this is actually a way to activate a mark ;; you have to move your point to one side (push-mark right-paren) (goto-char left-paren) (activate-mark)))) </code></pre> <p>When you use primary selection to select something around, you can't save the position of your current point(you named it caret). To save current position and have some selection, you can use <a href="http://www.emacswiki.org/emacs/SecondarySelection" rel="nofollow">secondary selection</a>.</p> <pre><code>(require 'second-sel) (global-set-key [(control meta ?y)] 'secondary-dwim) (define-key esc-map "y" 'yank-pop-commands) (define-key isearch-mode-map "\C-\M-y" 'isearch-yank-secondary) (defun secondary-selection-deactivate() (interactive) (x-set-selection 'SECONDARY nil) (move-overlay mouse-secondary-overlay (point-min) (point-min) (current-buffer))) (defun secondary-selection-in-this-buffer-p() (and (x-get-selection 'SECONDARY) (overlayp mouse-secondary-overlay) (eq (current-buffer) (overlay-buffer mouse-secondary-overlay)))) (defun set-secondary-selection-around-parens() (interactive) (let ( (right-paren (save-excursion (re-search-forward ")" nil t))) (left-paren (save-excursion (re-search-backward "(" nil t)))) (when (and right-paren left-paren) (primary-to-secondary left-paren right-paren) ))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload