all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Select/highlight and *copy* matches of some regex
Date: Tue, 28 Jun 2022 00:41:25 +0200	[thread overview]
Message-ID: <87bkudhgq2.fsf@dataswamp.org> (raw)
In-Reply-To: 87fsjphhar.fsf@dataswamp.org

>>> The first part, highlighting all matches, is not
>>> a problem. But I haven't found a way yet to then extract
>>> all matches.
>>
>> Is this (suitably tweaked) good enough?
>>
>> (let ((matches ""))
>>   (while (re-search-forward "lang=.." nil t)
>>     (setq matches (concat matches (match-string 0) "\n")))
>>   (kill-new matches))
>
> I have something like that [...]
>
> (defun re-make-list-forward (re &optional beg end)
>   (interactive
>    (when (use-region-p)
>      (list
>       (read-regexp "re: ")
>       (region-beginning)
>       (region-end) )))

Oups, that's no good if called interactively without a region.
I changed that ...

But I don't know what's the right thing to do when called from
Lisp with 'beg' and 'end' implicitly nil _and_ there is
a region?

Either use the region or consider that an interactive feature
only and set 'beg' and 'end' to the default `point-min' and
`point-max'?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/re-make-list.el

(defun re-make-list-forward (re &optional beg end)
  (interactive
   (list
    (read-regexp "re: ")
    (when (use-region-p) (region-beginning))
    (when (use-region-p) (region-end)) )
  (or beg (setq beg (point)))
  (or end (setq end (point-max)))
  (save-excursion
    (let ((matches))
      (goto-char beg)
      (while (re-search-forward re end t)
        (push (match-string-no-properties 0) matches) )
      matches) ))
(defalias 're-make-list #'re-make-list-forward)

(defun re-make-list-backward (re &optional beg end)
  (interactive
   (list
    (read-regexp "re: ")
    (when (use-region-p) (region-beginning))
    (when (use-region-p) (region-end)) )
  (or beg (setq beg (point)))
  (or end (setq end (point-max)))
  (save-excursion
    (let ((matches))
      (goto-char end)
      (while (re-search-backward re beg t)
        (push (match-string-no-properties 0) matches) )
      matches) ))

;; Below are 139 colors, so the list should have 139 items
;; <https://www.rapidtables.com/web/color/RGB_Color.html>
;;
;; (length (re-make-list-forward  "#[0-9a-f]\\{6\\}")) ; 139
;; (length (re-make-list-backward "#[0-9a-f]\\{6\\}")) ; 139
;;
;; maroon                  #800000
;; dark red                #8b0000
;; brown                   #a52a2a
;; firebrick               #b22222
;; crimson                 #dc143c
;; red                     #ff0000
;; tomato                  #ff6347
;; coral                   #ff7f50
;; indian red              #cd5c5c
;; light coral             #f08080
;; dark salmon             #e9967a
;; salmon                  #fa8072
;; light salmon            #ffa07a
;; orange red              #ff4500
;; dark orange             #ff8c00
;; orange                  #ffa500
;; gold                    #ffd700
;; dark golden rod         #b8860b
;; golden rod              #daa520
;; pale golden rod         #eee8aa
;; dark khaki              #bdb76b
;; khaki                   #f0e68c
;; olive                   #808000
;; yellow                  #ffff00
;; yellow green            #9acd32
;; dark olive green        #556b2f
;; olive drab              #6b8e23
;; lawn green              #7cfc00
;; chart reuse             #7fff00
;; green yellow            #adff2f
;; dark green              #006400
;; green                   #008000
;; forest green            #228b22
;; lime                    #00ff00
;; lime green              #32cd32
;; light green             #90ee90
;; pale green              #98fb98
;; dark sea green          #8fbc8f
;; medium spring green     #00fa9a
;; spring green            #00ff7f
;; sea green               #2e8b57
;; medium aqua marine      #66cdaa
;; medium sea green        #3cb371
;; light sea green         #20b2aa
;; dark slate gray         #2f4f4f
;; teal                    #008080
;; dark cyan               #008b8b
;; aqua                    #00ffff
;; cyan                    #00ffff
;; light cyan              #e0ffff
;; dark turquoise          #00ced1
;; turquoise               #40e0d0
;; medium turquoise        #48d1cc
;; pale turquoise          #afeeee
;; aqua marine             #7fffd4
;; powder blue             #b0e0e6
;; cadet blue              #5f9ea0
;; steel blue              #4682b4
;; corn flower blue        #6495ed
;; deep sky blue           #00bfff
;; dodger blue             #1e90ff
;; light blue              #add8e6
;; sky blue                #87ceeb
;; light sky blue          #87cefa
;; midnight blue           #191970
;; navy                    #000080
;; dark blue               #00008b
;; medium blue             #0000cd
;; blue                    #0000ff
;; royal blue              #4169e1
;; blue violet             #8a2be2
;; indigo                  #4b0082
;; dark slate blue         #483d8b
;; slate blue              #6a5acd
;; medium slate blue       #7b68ee
;; medium purple           #9370db
;; dark magenta            #8b008b
;; dark violet             #9400d3
;; dark orchid             #9932cc
;; medium orchid           #ba55d3
;; purple                  #800080
;; thistle                 #d8bfd8
;; plum                    #dda0dd
;; violet                  #ee82ee
;; magenta / fuchsia       #ff00ff
;; orchid                  #da70d6
;; medium violet red       #c71585
;; pale violet red         #db7093
;; deep pink               #ff1493
;; hot pink                #ff69b4
;; light pink              #ffb6c1
;; pink                    #ffc0cb
;; antique white           #faebd7
;; beige                   #f5f5dc
;; bisque                  #ffe4c4
;; blanched almond         #ffebcd
;; wheat                   #f5deb3
;; corn silk               #fff8dc
;; lemon chiffon           #fffacd
;; light golden rod yellow #fafad2
;; light yellow            #ffffe0
;; saddle brown            #8b4513
;; sienna                  #a0522d
;; chocolate               #d2691e
;; peru                    #cd853f
;; sandy brown             #f4a460
;; burly wood              #deb887
;; tan                     #d2b48c
;; rosy brown              #bc8f8f
;; moccasin                #ffe4b5
;; navajo white            #ffdead
;; peach puff              #ffdab9
;; misty rose              #ffe4e1
;; lavender blush          #fff0f5
;; linen                   #faf0e6
;; old lace                #fdf5e6
;; papaya whip             #ffefd5
;; sea shell               #fff5ee
;; mint cream              #f5fffa
;; slate gray              #708090
;; light slate gray        #778899
;; light steel blue        #b0c4de
;; lavender                #e6e6fa
;; floral white            #fffaf0
;; alice blue              #f0f8ff
;; ghost white             #f8f8ff
;; honeydew                #f0fff0
;; ivory                   #fffff0
;; azure                   #f0ffff
;; snow                    #fffafa
;; black                   #000000
;; dim gray / dim grey     #696969
;; gray / grey             #808080
;; dark gray / dark grey   #a9a9a9
;; silver                  #c0c0c0
;; light gray / light grey #d3d3d3
;; gainsboro               #dcdcdc
;; white smoke             #f5f5f5
;; white                   #ffffff

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2022-06-27 22:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 15:52 Select/highlight and *copy* matches of some regex Joost
2022-06-27 16:12 ` tomas
2022-06-27 17:16   ` Joost
2022-06-27 17:44     ` tomas
2022-06-28  4:40     ` Visuwesh
2022-06-28 19:52       ` Emanuel Berg
2022-06-29 21:40       ` Joost Kremers
2022-06-30  6:05         ` Emanuel Berg
2022-06-28  9:29     ` Daniel Martín
2022-06-28 10:33       ` tomas
2022-06-27 20:56 ` Stephen Berman
2022-06-27 21:09   ` Joost Kremers
2022-06-27 22:26     ` Emanuel Berg
2022-06-27 22:29     ` Emanuel Berg
2022-06-27 22:41       ` Emanuel Berg [this message]
2022-06-27 23:11         ` DWIM interface (was: Re: Select/highlight and *copy* matches of some regex) Emanuel Berg
2022-06-27 22:44       ` Select/highlight and *copy* matches of some regex Emanuel Berg
2022-06-28  4:43         ` tomas
2022-06-28  5:37           ` Emanuel Berg
2022-06-28  4:42   ` tomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bkudhgq2.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.