From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: Functionality to maintain function prototypes in C Date: Fri, 28 Oct 2016 18:30:01 -0700 Message-ID: References: <87wpgsduir.fsf@informatimago.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1477704669 15796 195.159.176.226 (29 Oct 2016 01:31:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Oct 2016 01:31:09 +0000 (UTC) Cc: "Pascal J. Bourguignon" To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Oct 29 03:31:05 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0ITu-00017M-Go for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Oct 2016 03:30:46 +0200 Original-Received: from localhost ([::1]:52726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0ITx-0005Ue-0O for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Oct 2016 21:30:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0ITZ-0005UW-52 for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 21:30:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0ITX-0002TH-Hg for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 21:30:25 -0400 Original-Received: from mail-yw0-x234.google.com ([2607:f8b0:4002:c05::234]:35784) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c0ITX-0002TA-EA for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 21:30:23 -0400 Original-Received: by mail-yw0-x234.google.com with SMTP id h14so108299225ywa.2 for ; Fri, 28 Oct 2016 18:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=vXpAAr786CSDJJ9FNwzSGtiXmDp/9aWesWMoodcwqC0=; b=A0hu2AI4oozka7Hm7R9QVdPXRZzUDMMETvLVYq+Tg8UKjlk1mfh3neBoOKUqd1Qkgy iYwsC8QLpJxZCvj8uKA48BDw4w8ybfAX85kqDc8WlUkOe1Vyy5ouLOAfpIzVi6qrmEVi gvwZADf9XVm8gedrUqbLiiU/uw/nXZCYaoPV9BA0quaNU6b3TjFdWhx8mKRwNEwQn1o/ OywjZ8XkelBSGswTMEh8BpCHvt1E0HarrQCuE0kwZ9rUj2lx1FbhyalAhbcuGd5j0Wqd QIHeH+EJ07uQyBT+x2TxkDM2GpA7Us84JG/t0xor/KwBQj4GlXMh3IiyL+uL/7Wk93yH oe6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=vXpAAr786CSDJJ9FNwzSGtiXmDp/9aWesWMoodcwqC0=; b=Jq3kMaTfdfGQE9SqCB3UPqmtHJb0XHp2qMyx5A8imDuvbQCrBrxnwi+CS1SZC495GO Gi0XQ8ugz0UvCEdQW/taQJV0pkFZsKVNnT7nHvZ47hFLntuXBbC/dqIvXZCGB5gmr2Xy 5u5SmIF7epM01sC0tr19ze39HBLj9/lYx9EO9IFNUDy0iCOzFrRWZZjvr+evqUglg9Rg BeoKQXEcZJXlJQyD1GcvcoEpTupKgRCWrbKK4b+KT3bewfadIzrJBUzyRoFF1QBvp173 Ki4h5qMPIFnNi2fNCgyvY43K5RkA3wZyOVyObY5WndcYoSIv40JkAvD1Q3MwVartF3b2 NHdg== X-Gm-Message-State: ABUngvdqQra7oowUXbRvys1Dr6RRBRzwbvxTIEk9TC+QsLmoWo4IM31/NOVHpDt0cnjYBTxuO333VY2vg23gkw== X-Received: by 10.13.254.135 with SMTP id o129mr14181148ywf.198.1477704622328; Fri, 28 Oct 2016 18:30:22 -0700 (PDT) Original-Received: by 10.37.171.170 with HTTP; Fri, 28 Oct 2016 18:30:01 -0700 (PDT) In-Reply-To: <87wpgsduir.fsf@informatimago.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::234 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111625 Archived-At: Pascal J. Bourguignon wrote: > The first time, move the point where you want the forward signatures to > be inserted and M-x c-update-forward-defun-signatures RET > > Then M-x c-update-forward-defun-signatures RET again will update the > same section, wherever the point is. > > Now, you will have to move all the type definition used in the function > signature before this section=E2=80=A6 Thanks for posting this - there have definitely been times I could have used it. I made one modification to the part where it searches for an existing block of declarations, changing the regexp to: (format "%s\\(.\\|\n\\)*%s" section-begin section-end) Because "." doesn't match newlines. I also gave both functions an optional argument STATIC-ONLY to only collect functions declared static, since that's generally what I've wanted. The result with those tweaks, in case it's useful to anyone: (defun c-collect-defun-signatures (&optional static-only) "Return a list of C function signatures found in the buffer." (let ((regexp (if static-only "\\(static .*(.*)\\)[^(){}]*{" "\\(.*(.*)\\)[^(){}]*{")) (signatures '()) (last-defun -1)) (goto-char (point-min)) (end-of-defun) (beginning-of-defun) (while (/=3D last-defun (point)) (setf last-defun (point)) (when (re-search-forward regexp nil t) (push (match-string 1) signatures)) (end-of-defun) (end-of-defun) (beginning-of-defun)) signatures)) (defun c-update-forward-defun-signatures (&optional static-only) "Update the forward function signatures. If a section doesn't already exist, creates it at point." (interactive "*P") (let ((signatures (save-excursion (nreverse (c-collect-defun-signatures static-only)))) (section-begin "// BEGIN FORWARD FUNCTION SIGNATURES\n") (section-end "// END FORWARD FUNCTION SIGNATURES\n")) (goto-char (or (save-excursion (goto-char (point-min)) (when (re-search-forward (format "%s\\(.\\|\n\\)*%s" section-begin section-end) nil t) (delete-region (match-beginning 0) (match-end 0)) (match-beginning 0))) (point))) (insert section-begin) (dolist (signature signatures) (insert signature ";\n")) (insert section-end)))