From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Elisp: can't read buffer content with with-current-buffer Date: Thu, 02 Jun 2022 22:33:08 +0200 Message-ID: <87k09y3in7.fsf@gnu.org> References: <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="3316"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.26; emacs 29.0.50 Cc: help-gnu-emacs@gnu.org To: Alessandro Bertulli Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 02 22:40:05 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 1nwrbx-0000eW-HR for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 22:40:05 +0200 Original-Received: from localhost ([::1]:37654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwrbw-00028E-2B for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 16:40:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwraq-00026x-RJ for help-gnu-emacs@gnu.org; Thu, 02 Jun 2022 16:38:57 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:40084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwraq-0005rX-Fk; Thu, 02 Jun 2022 16:38:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=5jKsanIJucl1NMNNHtm0oTevDg41B7bNgyGbw99cIm4=; b=A3QwwYBJMxa9dJ sTJAuIgVo55KEWmeSKWCbQz4zX5qQ3dp0r6F39YBN94eHcPB9Y5SyK+osGHL9OxQy9nXmOHprYJhQ dS9dcqoEbjWxq9+kyQkh5W0HUDPXs+G3lvQNKGh7x4YUIk2Zx2j6fadOzI+64zWKNT7LoaprEK/TP GooOoKmyrUC5j4HC3d8AushEIBVNRNw/keMIkTEyi1n3YFxU4f+1sn0PGMGg4Dqfw8d8gtcrbaiP8 uGMsNZle6djeJvv/F59rJswKgT1/nAktv3TWB+EYbXxyXRe/urH+qVLtalWKzgSnND644/7MP/xgu 3Zyn9YsCubxSMQXCFVKA==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:33549) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwraq-0001nf-8P; Thu, 02 Jun 2022 16:38:56 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id CF46A27C0054; Thu, 2 Jun 2022 16:38:55 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 02 Jun 2022 16:38:55 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrleeggddvvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpehffgfhvfevufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefvrghsshhi lhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqnecuggftrfgrthhtvghrnhepud ejtdehuddvleffjeekteegvdehleehvdeufefhueekkeekhedvgfeggeffvefgnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhrnhdomh gvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeefkeejkeegqdeifeehvdel kedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 Jun 2022 16:38:55 -0400 (EDT) In-reply-to: <8735gn9fq2.fsf@gmail.com> 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:137488 Archived-At: Alessandro Bertulli writes: Hi Alessandro, > 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? No. You call `async-shell-command' which just starts the command and immediately returns (without waiting for it to finish) and then your output-buffer hasn't received the grep output yet. So use `shell-command' instead. And instead of using set-text-properties to remove properties, use (buffer-substring-no-properties (point-min) (point-max)) Bye, Tassilo