LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2022, 08:33 AM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
Emacs function for isearch


I want to make an interactive emacs function that performs incremental search or highlight regexp.
A difficulty I have is how to accept the user regexp once he selects "highlight" or "unhighlight".


Code:
(defun xepty-isearch (action)
  "Incremental search.
C-s       Forward repeat incremental search again.
C-r       Backward repeat incremental search again.
M-s h r   Highlight regular expression (‘highlight-regexp’)
M-s h u   Unhighlight regular expression
"

  (interactive
    (list
     (let ( (cseq '("backward" "highlight" "unhighlight" "forward")) )
       (completing-read "Search: " cseq nil t "forward"))))

   (pcase action
     ("forward"   (isearch-forward))
     ("backward"  (isearch-backward))
     ("highlight"   
         (let ( (regexp (read-string "Regexp: ")) )
	    (unhighlight-regexp regexp)))
     ("unhighlight" (unhighlight-regexp regexp))) )

Last edited by Faki; 10-12-2022 at 11:12 AM.
 
Old 10-12-2022, 09:17 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
I don't understand. Emacs can do incremental search by default. What are you looking for?
https://www.gnu.org/software/emacs/m...al-Search.html
 
1 members found this post helpful.
Old 10-12-2022, 11:10 AM   #3
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
I want to use "highlight-regexp" which requires "regexp". But if I call "M-x highlight-regexp" I get
a minibuffer prompt. In the interactive clause of my function, I thought that calling "highlight-regexp"
might display the prompt for the user. But it does not work in the way I describe, as I never see the prompt
from "highlight-regexp".

Code:
(highlight-regexp regexp)
 
Old 10-13-2022, 10:17 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Not that my version is up to date, I have 27.1 and it automatically highlights search results. My profile doesn't do anything special wrt faces or highlighting.
 
  


Reply

Tags
emacs, search



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
emacs lisp: define function to be used inside emacs stateless Programming 1 03-01-2013 05:04 PM
How can I get emacs -nw when I call emacs from a terminal but GUI emacs elsewhere? Blackened Justice Linux - Newbie 4 09-08-2011 07:57 AM
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 05:00 PM
where is the .emacs file in the emacs source code tarball? aizkorri Programming 2 01-13-2007 02:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration