From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alessandro Bertulli Newsgroups: gmane.emacs.help Subject: Elisp: can't read buffer content with with-current-buffer Date: Thu, 02 Jun 2022 18:45:25 +0200 Message-ID: <8735gn9fq2.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40543"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 02 18:46:33 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 1nwnxx-000AR8-D0 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 18:46:33 +0200 Original-Received: from localhost ([::1]:45288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwnxv-0007Fi-QZ for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 12:46:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwnx2-0007Dz-AS for help-gnu-emacs@gnu.org; Thu, 02 Jun 2022 12:45:38 -0400 Original-Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:41857) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwnwz-0000UQ-SJ for help-gnu-emacs@gnu.org; Thu, 02 Jun 2022 12:45:35 -0400 Original-Received: by mail-ej1-x634.google.com with SMTP id u12so11061064eja.8 for ; Thu, 02 Jun 2022 09:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=43dR4m70tg5N8mcT1FAH5Xw0Vks3/Bf6RVteOGIMV2I=; b=X3M5EcnSalJ4pHrCvcSjeAfVv5OqdiUv+jrKeYFtLE0kTomRxeEpXh5WKd8dz9KcnL 4tgbUnloYclUWDr2SgrC9sTsJQuM3g9jvgLjNHWQ5RGkeCnu96t1m6gioO+aAeawwXUE cJVcCKukEPonLTEN8CCnsxUu05Oiboq/Khd/LZH47VNCcZdUoJCkWKk8GQy7kPCu7wT3 m04Pa5syHx9qs52GcJ8yEONr0KAGljMLqSuP15h1ZOgOat8BLqe4OOgS6flLdJgOy/z0 rrENS8lXHbpFLnbVDl+0mvfn/8b0mkF1hy136+IWb3Jknci3ALH7xHlIRja274oliuME XH0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=43dR4m70tg5N8mcT1FAH5Xw0Vks3/Bf6RVteOGIMV2I=; b=HmQ6o6L4OWOLwElWenZ3B5Ao/sQmN2hQkjm9GL2H63GmpsxgelloAz2TbjJ40FHFT9 LBmlORGulBQi/0Cue7oNLwiDm/sP0pVmUurHZh1vzfUndRK0f5wWHV/lpKVvYDttNp8W Ayq7oKXIJQrIicEfojsLzIZ/Pf7GO4Urg8mZgY+fbYZ1MfSxznfd/fSGCrGlBr2U6V8S SJAQ228EWPiTtyW0cCEEEx1yTGkkBfgkFGJJHeC9NTkrNK+BIHLVMNTvjxgtrNfeX3R/ 6in9mYmF4R4XFAxsNUXR0ceWQ7FUErVg3yk5xgPhdJlWx0nVaZ9uxTr0nvei5CZ8QZvx lOVA== X-Gm-Message-State: AOAM530tEIObUNmNyEGKrpXl9GHU6sRm0TXeZA3LMsv0dgbQi98Vtwkw ea7Awplp9+Y8C1V6fJ+WCpWl5N/LkbcIHg== X-Google-Smtp-Source: ABdhPJxCAvy8YzWRE2Btz+4GifIHd6XTCzLMPsyTbpz259c/8W2Olkpvixc7IPJK5X5wUB2uYV9ROQ== X-Received: by 2002:a17:907:d0d:b0:6fe:d87c:cbc3 with SMTP id gn13-20020a1709070d0d00b006fed87ccbc3mr5112246ejc.325.1654188330914; Thu, 02 Jun 2022 09:45:30 -0700 (PDT) Original-Received: from commodoroII (2-235-154-9.ip228.fastwebnet.it. [2.235.154.9]) by smtp.gmail.com with ESMTPSA id j3-20020a170906094300b0070ad296e4b0sm800114ejd.186.2022.06.02.09.45.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 09:45:30 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=alessandro.bertulli96@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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:137486 Archived-At: 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