From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Functionality to maintain function prototypes in C Date: Fri, 28 Oct 2016 23:38:04 +0200 Organization: Informatimago Message-ID: <87wpgsduir.fsf@informatimago.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1477698174 4699 195.159.176.226 (28 Oct 2016 23:42:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 28 Oct 2016 23:42:54 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) 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 01:42:49 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 1c0GnE-000889-6m for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Oct 2016 01:42:36 +0200 Original-Received: from localhost ([::1]:52345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0GnG-0000dt-Dc for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Oct 2016 19:42:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0ErY-0000cD-6n for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 17:38:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0ErU-00086Z-SG for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 17:38:56 -0400 Original-Received: from [195.159.176.226] (port=57608 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c0ErU-00084m-LD for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 17:38:52 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1c0Er9-0005fP-6k for help-gnu-emacs@gnu.org; Fri, 28 Oct 2016 23:38:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 91 Original-X-Complaints-To: usenet@blaine.gmane.org Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en Cancel-Lock: sha1:ZjljYmVlMDM1N2QyNWQ0Y2I4MjI0N2RkOWVlMmY3Y2JmOTk2MWExYg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-Mailman-Approved-At: Fri, 28 Oct 2016 19:42:10 -0400 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:111624 Archived-At: Nikolai Weibull writes: > Hi! > > C has the issue of being compiled in a single pass. After many years > of working around this issue by defining my static functions in > reverse order, which is good for the compiler, but bad for the user, > I’m now looking to try writing them in a more natural order. The main > issue with this is maintaining the static-function prototypes. I’ve > looked around, but I can’t find a minor mode that’ll add, update, and > remove static-function prototypes automatically, either by command or > at file save, so I was hoping that someone here could point me in the > right direction. Once upon a time, I used macros: In a file named BcInterface.h: #define PROCEDURE(nam,prm,res) extern res nam prm ; In a file named BcImplementation.h: #define PROCEDURE(nam,prm,res) res nam prm Then it was a simple matter of: ( cat ${source}_header_prefix grep PROCEDURE ${source}.c cat ${source}_header_suffix ) > ${source}.h But that was before I used emacs :-) ;;; Code: (defun c-collect-defun-signatures () "Return a list of C function signatures found in the buffer." (let ((signatures '()) (last-defun -1)) (goto-char (point-min)) (end-of-defun) (beginning-of-defun) (while (/= last-defun (point)) (setf last-defun (point)) (when (re-search-forward "\\(.*(.*)\\)[^(){}]*{" nil t) (push (match-string 1) signatures)) (end-of-defun) (end-of-defun) (beginning-of-defun)) signatures)) (defun c-update-forward-defun-signatures () "Update the forward function signatures. If a section doesn't already exist, creates it at point." (interactive) (let ((signatures (save-excursion (nreverse (c-collect-defun-signatures)))) (section-begin "\n// BEGIN FORWARD FUNCTION SIGNATURES\n") (section-end "\n// END FORWARD FUNCTION SIGNATURES\n")) (goto-char (or (save-excursion (goto-char (point-min)) (when (re-search-forward (format "%s.*%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))) (provide 'c-defun) ;;; c-defun.el ends here 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… -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk