From: Alessandro Bertulli <alessandro.bertulli96@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Elisp: can't read buffer content with with-current-buffer
Date: Thu, 02 Jun 2022 18:45:25 +0200 [thread overview]
Message-ID: <8735gn9fq2.fsf@gmail.com> (raw)
Hi all!
I'm trying to set up some custom Elisp function to help me run Java
programs. Since it's possible I have different classes containing a main
method (for instance, when developing multi process or client-server
applications) I wanted to use completing-read. Therefore, I need a
list/function for completion. To do so, I need to scan the project I'm
working on, and search for the main methods that can be run. No problem
here, I can do that using grep and regexp. But then I don't know how to
collect those results in a list!
Specifically, let's say I have the directory "my_project" containing
some Java files. I want a list of strings, each one being one of the
files returned by grep, like:
'("~/my_project/src/main/java/ClassOne.java"
"~/my_project/src/main/java/ClassTwo.java")
In this function I wrote, however, it seems I can't do that:
(defun get-main-method-list ()
"Scan the project for main methods to run."
(interactive)
(let* ((project-root (projectile-acquire-root))
(output-buffer (get-buffer-create "*java-grep*")))
(async-shell-command (format "grep --include=\\*.java -rnwl \'%s\' -e \'%s\'"
project-root
"public[[:space:]]\\+static[[:space:]]\\+void[[:space:]]\\+main")
output-buffer
output-buffer)
(with-current-buffer output-buffer
(let ((buffer-content (buffer-string)))
(print buffer-content) ;; debug
(set-text-properties 0 (length buffer-content) nil buffer-content)
(split-string buffer-content "\n")))))
See where I put a debug (print): it prints nothing or newlines, and the
function seems to return '(""). Is this a problem in using
with-current-buffer? If no, what am I getting wrong? Is this the
preferred way to tokenize a buffer into a list of strings?
Thanks for your time, have a nice day!
Alessandro
next reply other threads:[~2022-06-02 16:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-02 16:45 Alessandro Bertulli [this message]
2022-06-02 20:33 ` Elisp: can't read buffer content with with-current-buffer Tassilo Horn
2022-06-02 22:48 ` Alessandro Bertulli
2022-06-03 6:25 ` Tassilo Horn
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=8735gn9fq2.fsf@gmail.com \
--to=alessandro.bertulli96@gmail.com \
--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.
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).