highlighting all occurrences of the same piece of text
Eric Bouyoux
eric.bouyoux at insidefr.com
Wed Aug 16 11:30:05 CEST 2006
Mike MacGillis a écrit :
> Hi Eric,
> if you could send that macro to me when you have a chance that would be great.
> Cheers
> Mike
>
Hi,
I have attached a macro file that contains my own macros and the part of
my .nedit file that maps macros to bindkeys. For exemple, CTRL+3 will
highlight in yellow all occurrences of the selected pattern and CTRL+5
will deselect all highlighted parts.
Regards.
Eric.
> -----Original Message-----
> From: discuss-bounces at nedit.org [mailto:discuss-bounces at nedit.org]On
> Behalf Of Eric Bouyoux
> Sent: 14 August 2006 18:58
> To: General NEdit discussion list
> Subject: Re: highlighting all occurrences of the same piece of text
>
>
>
> Mike MacGillis a écrit :
>
> Hello,
> I have been trying to get nedit to highlight all the occurrences of a certain p
> attern within a text file. However, there doesn't seem to be an easy way of doi
> ng this.
> I have noticed that this feature exists on emacs and is quite useful when looki
> ng at large text files. Nedit is my editor of choice but this feature would be
> very handy. Does it currently exist within nedit?
> Cheers
> Mike
>
>
> Unless otherwise expressly stated, this message does not create or vary any con
> tractual relationship between you and ARC International. The contents of this
> e-mail may be confidential and if you have received it in error, please delete
> it from your system, destroy any hard copies and telephone the above number. I
> ncoming emails to ARC may be subject to monitoring other than by the addressee.
> EL
>
>
> Hi,
> Someone of this mailing list gave me a macro that was doing more or
> less this. I adapted it and mapped it to a bindkey. The macro and
> bindkey mapping is on my workstation. I can send it to you in 2 days.
> I did not succeed to map it to the bindkey I wanted but it works.
> Regards.
> Eric.
> Unless otherwise expressly stated, this message does not create or vary any contractual relationship between you and ARC International. The contents of this e-mail may be confidential and if you have received it in error, please delete it from your system, destroy any hard copies and telephone the above number. Incoming emails to ARC may be subject to monitoring other than by the addressee. EL
>
-------------- next part --------------
nedit.macroCommands: \
find_all:Ctrl+4::: {\n\
jf_find_all("")\n\
}\n\
clear_find_all:Ctrl+5::: {\n\
jf_clear_find_all("")\n\
}\n\
find_all_selected:Ctrl+3::: {\n\
jf_find_all_selected("")\n\
}\n\
toggleLitteral:Ctrl+D::: {\n\
toggleLitteral("")\n\
}\n\
findLitteralF:Ctrl+E::: {\n\
findLitteralF("")\n\
}\n\
findLitteralB:Shift+Ctrl+E::: {\n\
findLitteralB("")\n\
}\n
-------------- next part --------------
define replaceALot {
replace_in_string(Call, ebeb)
}
# Requires version 5.4RC*2* (not RC1) or above of NEdit.
# Add the file to autoload.nm or load it from there
# Make a menu entry with the call jf_find_all() and another one with
# jf_clear_find_all()
# Takes a string as unique name of a rangeset
# If a single rangeset with name exists in window, returns its id.
# If no rangeset with name exists in window, creates one and returns its id.
# If more than one rangesets with name exist already in window, returns -1.
define jf_init_rangeset {
rname = $1
test = rangeset_get_by_name(rname)
if (test[] > 1) {
return -1
}
if (test[] == 1) {
return(test[0])
}
if (test[] == 0) {
a = rangeset_create()
rangeset_set_name(a, rname)
return(a)
}
}
define jf_find_all {
rbasename = "jf_find_all"
find_types[1] = "literal"
find_types[2] = "case"
find_types[3] = "word"
find_types[4] = "caseWord"
find_types[5] = "regexNoCase"
find_types[6] = "regex"
if ($selection_start == -1) {
find_from = 0
}
else {
find_from = $selection_start
}
if ($selection_end == -1) {
find_to = $text_length
}
else {
find_to = $selection_end
}
search_for = string_dialog( "Find", "Literal", "Cased Literal", "Word","Cased Word", "RegEx", "Cased RegEx")
if ($string_dialog_button == 0) return
find_type = find_types[$string_dialog_button]
# snap color
color = jf_get_available_color()
rangeset = jf_init_rangeset( rbasename ":" color)
rangeset_set_color( rangeset, color)
find_at = search( search_for, find_from, find_type)
find_thru = $search_end
while (find_at >= find_from & find_thru <= find_to) {
rangeset_add( rangeset, find_at, find_thru )
find_from = find_thru + 1
find_at = search( search_for, find_from, find_type)
find_thru = $search_end
}
}
define jf_find_all_selected {
rbasename = "jf_find_all_selected"
find_from = 0
find_to = $text_length
search_for = get_selection()
#search_for = string_dialog( "Find", "Literal", "Cased Literal", "Word","Cased Word", "RegEx", "Cased RegEx")
#if ($string_dialog_button == 0) return
#find_type = find_types[$string_dialog_button]
# snap color
color = jf_get_available_color()
rangeset = jf_init_rangeset( rbasename ":" color)
rangeset_set_color( rangeset, color)
find_at = search( search_for, find_from)
find_thru = $search_end
while (find_at >= find_from & find_thru <= find_to) {
rangeset_add( rangeset, find_at, find_thru )
find_from = find_thru + 1
find_at = search( search_for, find_from)
find_thru = $search_end
}
}
define jf_clear_find_all {
active_rangesets = $rangeset_list
for (i = 0; i < active_rangesets[]; i++) {
a = rangeset_info(active_rangesets[i])
pos = search_string(a["name"], "jf_find_all", 0)
if (pos == 0) {
rangeset_destroy(active_rangesets[i])
}
}
}
define jf_get_available_color {
used_colors = $empty_array
rgb_colors =\
"yellow Orange Coral1 Orchid1 SkyBlue1 SpringGreen2 #f0f050 Gold1 LightPink1 \
Plum1 CadetBlue2 PaleGreen1 khaki1 LightSalmon1 PaleVioletRed1 #D8A9FF \
aquamarine2 DarkOliveGreen1 "
active_rangesets = $rangeset_list
for (i = 0, j = 0; i < active_rangesets[]; i++) {
a = rangeset_info(active_rangesets[i])
pos = search_string(a["name"], "jf_find_all:", 0)
if (pos == 0) {
used_colors[j++] = substring(a["name"], $search_end, length(a["name"]))
}
}
for (i = 0; i < used_colors[]; i++) {
pos = search_string(rgb_colors, used_colors[i], 0)
if (pos != -1) {
rgb_colors = substring(rgb_colors, $search_end + 1, length(rgb_colors))
}
}
pos = search_string(rgb_colors, " ", 0)
if (pos != -1) {
return(substring(rgb_colors, 0, pos))
}
else {# failed
return -1
}
}
$case = "false"
define toggleLitteral {
if ($case == "true") {
$case = "false"
}
else {
$case = "true"
}
}
define findLitteralB {
if ($case == "true") {
find_selection("case", "backward")
}
else {
find_selection("literal", "backward")
}
}
define findLitteralF {
if ($case == "true") {
find_selection("case", "forward")
}
else {
find_selection("literal", "forward")
}
}
More information about the Discuss
mailing list