all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: daanturo <daanturo@gmail.com>
To: Philip Kaludercic <philipk@posteo.net>
Cc: emacs-devel@gnu.org
Subject: Re: A function to take the regexp-matched subsring directly
Date: Sun, 30 Oct 2022 23:46:10 +0700	[thread overview]
Message-ID: <831245da-8f0f-85b7-0cb7-e088157012d2@gmail.com> (raw)
In-Reply-To: <87wn8h9uy4.fsf@posteo.net>


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.




  reply	other threads:[~2022-10-30 16:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30 15:17 A function to take the regexp-matched subsring directly daanturo
2022-10-30 15:45 ` Philip Kaludercic
2022-10-30 16:46   ` daanturo [this message]
2022-10-30 17:26     ` Philip Kaludercic
2022-10-30 15:52 ` Stefan Monnier
2022-10-30 17:16   ` daanturo
2022-10-30 22:01     ` Stefan Monnier
2022-10-31  3:47       ` daanturo
2022-10-30 17:29   ` Philip Kaludercic
2022-10-30 22:07     ` Stefan Monnier
2022-10-31  8:56       ` Mattias Engdegård

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=831245da-8f0f-85b7-0cb7-e088157012d2@gmail.com \
    --to=daanturo@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=philipk@posteo.net \
    /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.