From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Select/highlight and *copy* matches of some regex Date: Tue, 28 Jun 2022 00:29:00 +0200 Message-ID: <87fsjphhar.fsf@dataswamp.org> References: <82a978f3-e974-4d8f-b87e-5707ffec0b5b@www.fastmail.com> <87pmitvn8x.fsf@rub.de> <875yklolp3.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20982"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:RVZbBIhf6120v0xWnnh169138DA= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 28 00:32:59 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5xHv-0005EZ-77 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 28 Jun 2022 00:32:59 +0200 Original-Received: from localhost ([::1]:40730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5xHt-0002Qg-Ia for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 27 Jun 2022 18:32:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5xFA-0002QH-Eb for help-gnu-emacs@gnu.org; Mon, 27 Jun 2022 18:30:10 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:36026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5xF6-0006CI-Se for help-gnu-emacs@gnu.org; Mon, 27 Jun 2022 18:30:06 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1o5xF4-0001Sb-1u for help-gnu-emacs@gnu.org; Tue, 28 Jun 2022 00:30:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138134 Archived-At: >>> 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 ... ;;; -*- 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 (when (use-region-p) (list (read-regexp "re: ") (region-beginning) (region-end) ))) (let ((b (or beg (point))) (e (or end (point-max))) ) (save-excursion (let ((matches '())) (goto-char b) (while (re-search-forward re e 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 (when (use-region-p) (list (read-regexp "re: ") (region-beginning) (region-end) ))) (let ((b (or beg (point))) (e (or end (point-max))) ) (save-excursion (let ((matches '())) (goto-char e) (while (re-search-backward re b t) (push (match-string-no-properties 0) matches) ) matches) ))) ;; Below are 139 colors, so the list should have 139 items ... ;; Colors: 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