[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A function to take the regexp-matched subsring directly
From: |
daanturo |
Subject: |
Re: A function to take the regexp-matched subsring directly |
Date: |
Sun, 30 Oct 2022 23:46:10 +0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 |
On 30/10/2022 22:45, Philip Kaludercic wrote:
> Is there a reason you find yourself working with strings as opposed to
> buffers? I've seen people try to force functional paradigms on Emacs
> when they do stuff like creating a list of lines in a buffer then
> iterating over these instead of using the (faster) buffer searching
> mechanisms. My worry is that functions like these, while useful per se,
> might make more people inclined to write unideomatic and wasteful code.
In my case, strings are usually file names and shell command outputs
```elisp
;; Get the commit hash returned by git blame
(shell-command-to-string "git blame -L 1,1 -- README")
"19dcb237b5b (Eli Zaretskii 2022-01-01 02:45:51 -0500 1) Copyright (C)
2001-2022 Free Software Foundation, Inc.
"
;; parse:
(regexp-match "^[^ ]+"
"19dcb237b5b (Eli Zaretskii 2022-01-01 02:45:51 -0500 1) Copyright (C)
2001-2022 Free Software Foundation, Inc.
")
=> "19dcb237b5b"
;; From `vc-revision-other-window''s file name, find the original name and the
revision
(regexp-match*
"\\(.*?\\)\\(?:\\.~\\(.*?\\)~\\)?\\'"
"/foo/bar.el.~main~")
=> ("/foo/bar.el.~main~" "/foo/bar.el" "main")
```
And many possible cases where the strings maybe buffer names or any not so long
strings that are not the size of a buffer.
--
Daanturo.