Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:40:36+00:00 2026-05-27T03:40:36+00:00

I need to select text in Emacs with regexp. And it would be for

  • 0

I need to select text in Emacs with regexp. And it would be for the best if I had an option to match only if match is surrounding caret.

Example:

text.....

<start oftext I want to select> text.....
text....
text.... <caret> text....
text....
text.... <end of text I want to select>

some other text

Edit: I am sorry that I obviously didn’t state my question clearly, so here is a clarification:

  • Caret was meant as the place where cursor is currently placed, not literal text to be matched
  • Start and end of text to be selected is just all the text that is in the document without any empty line.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:40:37+00:00Added an answer on May 27, 2026 at 3:40 am

    It’s not hard to find something around point in elisp. Just use two searches, forward and backward.

    (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))))
    

    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 secondary selection.

    (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)
        )))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 6 different select boxes and a text field which I need to
In my ASP.NET MVC project i need to select all text boxes that have
In my app I need to select some text in UITextview(editable) but I don't
I need to select an element based on its text in jQuery. For instance:
I need to prevent user from selecting text (select all or select a portion
I need to be able to select the text in a JLabel. Ive read
I have a query where I need to select text with a colon inside,
I need select's option to be actually selected on document ready depending on an
I need to select text from different paragraphs and make a span for showing
i have 10 textboxes and i need to select text from each one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.