From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: [External] : Re: User setup for emacs
Date: Mon, 11 Oct 2021 18:43:28 +0200 [thread overview]
Message-ID: <87ee8r1phr.fsf@zoho.eu> (raw)
In-Reply-To: 87ily31pof.fsf@zoho.eu
> I wonder what this code is supposed to do?
And this, that ain't in Emacs?
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; http://user.it.uu.se/~embe8573/emacs-init/search-regexp-in-files.el
;; https://dataswamp.org/~incal/emacs-init/search-regexp-in-files.el
(require 'cl-lib) ; cl-set-exclusive-or
(defun files-as-list (file-regexp)
(split-string
(with-temp-buffer
(call-process-shell-command
(format "ls %s" file-regexp) nil t) ; no INFILE, temp BUFFER
(buffer-substring (point-min) (point-max)) )))
(defun find-file-goto-line (file line)
(interactive)
(find-file-other-window file)
(goto-char (point-min))
(forward-line (1- line))
(window-resize nil (- 2 (window-height)) nil t) )
(defun regexp-hits-find-hit ()
(interactive)
(beginning-of-line)
(let ((file (thing-at-point 'filename nil))) ; NO-PROPERTIES
(end-of-line)
(search-backward "(")
(forward-char 1)
(let ((window (selected-window))
(line (thing-at-point 'number nil)) )
(forward-line 1)
(find-file-goto-line file line)
(select-window window) )))
(defun set-regexp-hits-keys ()
(local-set-key "\r" #'regexp-hits-find-hit)
(local-set-key "i" #'previous-line)
(local-set-key "k" #'forward-line) )
(defun search-regexp-in-files (file-regexp regexp)
(let ((paths (files-as-list file-regexp))
(regexp-hits "*regexp-hits*")
(hits nil) )
(get-buffer-create regexp-hits)
(let ((buffers (buffer-list))) ; get list to see if we opened the file -
(with-current-buffer regexp-hits
(goto-char (point-max))
(insert "---\n")
(set-regexp-hits-keys) )
(dolist (p paths)
(let ((buffer (find-file p)) ; here -
(kill-later (cl-set-exclusive-or buffers (buffer-list))) ) ; by comparing
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(while (re-search-forward regexp nil t) ; no BOUND, NOERROR
(setq hits t)
(let ((hit-line (line-number-at-pos))
(match (match-string-no-properties 0)) )
(with-current-buffer regexp-hits
(insert (format "%s [%s] (%s)\n" p match hit-line)) ))))
(when kill-later
(kill-buffer buffer) ))))
(if hits
(progn
(switch-to-buffer regexp-hits)
(set-buffer-modified-p nil)
(goto-char (point-min)) )
(message "no hits!") ))))
(when nil
;; find (- x x) - this is line 64
(search-regexp-in-files "~/.emacs.d/emacs-init/**/*.el" "(- \\(.*\\) \\1)")
;; find "kill" - should be some hits even for pacifists
(search-regexp-in-files "~/.emacs" "kill")
(search-regexp-in-files "~/.emacs.d/emacs-init/*.el" "kill")
;; find the construct (if a a b) if you want
;; to replace it with (or a b)
;; if it works, when applied to this file, it
;; should find the example above!
(search-regexp-in-files (buffer-file-name)
"([[:space:]\n]*if[[:space:]\n]+\\(.*\\)[[:space:]\n]+\\1[[:space:]\n]+\\(.*\\))" )
)
(provide 'search-regexp-in-files)
--
underground experts united
https://dataswamp.org/~incal
prev parent reply other threads:[~2021-10-11 16:43 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 15:30 User setup for emacs tolugboji via Users list for the GNU Emacs text editor
2021-10-08 16:16 ` tolugboji
2021-10-09 10:03 ` tolugboji
2021-10-10 14:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-10 14:33 ` tolugboji
2021-10-10 15:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-10 15:47 ` tolugboji
2021-10-10 16:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-10 17:11 ` tolugboji
2021-10-11 0:04 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-11 1:23 ` tolugboji
2021-10-11 3:09 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-10 18:00 ` Eduardo Ochs
2021-10-10 18:14 ` tolugboji
2021-10-10 18:31 ` [External] : " Drew Adams
2021-10-10 18:35 ` tolugboji
2021-10-10 19:02 ` [External] : " Drew Adams
2021-10-10 19:11 ` tolugboji
2021-10-11 0:02 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-10 23:59 ` [External] : " Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-11 0:34 ` Drew Adams
2021-10-11 3:13 ` Emanuel Berg via Users list for the GNU Emacs text editor
[not found] ` <SJ0PR10MB5488088380C0302344DA8E15F3B59@SJ0PR10MB5488.namprd10.prod.outlook.com>
[not found] ` <87r1cr1ql2.fsf@zoho.eu>
2021-10-11 16:30 ` Drew Adams
2021-10-11 16:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-11 16:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-11 16:43 ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ee8r1phr.fsf@zoho.eu \
--to=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).