From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Lisp primitives and their calling of the change hooks Date: Wed, 3 Jan 2018 12:45:43 +0000 Message-ID: <20180103124543.GA5435@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1514983718 13295 195.159.176.226 (3 Jan 2018 12:48:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 3 Jan 2018 12:48:38 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 03 13:48:34 2018 Return-path: Envelope-to: ged-emacs-devel@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 1eWiT7-0002tZ-Tw for ged-emacs-devel@m.gmane.org; Wed, 03 Jan 2018 13:48:30 +0100 Original-Received: from localhost ([::1]:51359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWiV7-00027o-4G for ged-emacs-devel@m.gmane.org; Wed, 03 Jan 2018 07:50:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWiUV-00025a-5d for emacs-devel@gnu.org; Wed, 03 Jan 2018 07:49:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWiUQ-00065X-A5 for emacs-devel@gnu.org; Wed, 03 Jan 2018 07:49:55 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:29229 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1eWiUP-00063I-VB for emacs-devel@gnu.org; Wed, 03 Jan 2018 07:49:50 -0500 Original-Received: (qmail 32645 invoked by uid 3782); 3 Jan 2018 12:49:44 -0000 Original-Received: from acm.muc.de (p548C73F3.dip0.t-ipconnect.de [84.140.115.243]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 03 Jan 2018 13:49:43 +0100 Original-Received: (qmail 5808 invoked by uid 1000); 3 Jan 2018 12:45:43 -0000 Content-Disposition: inline X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221548 Archived-At: Hello, Emacs. I've just had an interesting few days investigating our privitives' calling of before-change-functions and after-change-functions. In an ideal world, each primitive would call each of those hooks exactly once. However, we're not in an ideal world, and there are primitives which perform several (or many) distinct changes (e.g. transpose-regions or subst-char-in-region) where a single pair of hook calls wouldn't make sense. TL;DR: There are several, but not many, primitives where before-change-functions doesn't match after-change-functions. Here is how I went about this: 1. Extract a list of external functions in insdel.c from the section in lisp.h which declares them. Form a regexp from this list, and convert it into a grep regexp (by replacing '?' by '\?'. 2. grep -l *.c with this regexp. This gave these files: buffer.c callproc.c casefiddle.c cmds.c coding.c decompress.c editfns.c emacs.c fileio.c fns.c indent.c insdel.c print.c process.c search.c textprop.c xdisp.c xml.c 3. Using GNU cflow, a utility which creates call graphs for C files, create a reverse call graph (i.e. an "is called by" graph) for the 18 C files. 4. Analyse this graph with an elisp script to find all functions which, directly or indirectly, call signal_before_change or signal_after_change. 5. Filter this list of functions to leave only the lisp primitives (i.e. functions starting with "F"), and convert to Lisp names. Edit this list by hand to remove those primitives which don't change the buffer (most of them were removed). This left the following list: (add-face-text-property) (add-text-properties) (base64-decode-region) (base64-encode-region) (capitalize-region) (capitalize-word) (delete-and-extract-region) (delete-char) (delete-field) (delete-region) (downcase-region) (downcase-word) (erase-buffer) (indent-to) (insert) (insert-and-inherit) (insert-before-markers) (insert-buffer-substring) (insert-byte) (insert-char) (insert-file-contents) (move-to-column) (princ) (print) (put-text-property) (remove-list-of-text-properties) (remove-text-properties) (replace-buffer-contents) (replace-match) (self-insert-command) (set-buffer-multibyte) (set-text-properties) (subst-char-in-region) (terpri) (translate-region-internal) (transpose-regions) (upcase-initials-region) (upcase-region) (upcase-word) (write-char) (zlib-decompress-region) 6. Write and run a script which executes each of these primitives whilst counting the number of times it invokes before-change-hooks and after-change-hooks. Output messages where these numbers aren't 1 and 1. This gave the following: Primitive b-c-f calls a-c-f calls base64-encode-region 2 2 base64-decode-region 2 1 insert-file-contents 2 2 move-to-column-1 3 3 ; with the &optional ; which untabifies. replace-buffer-contents 123 123 set-buffer-multibyte 0 0 ; May have done nothing tranlate-region-internal 1 146 tranpose-regions 2 1 upcase-initials-region 1 0[*] upcase-region 1 0[*] zlib-decompress-region 0 0 erase-buffer 0 0 [*] In upcase-... there weren't any lower case characters in the buffer at the time. This list is incomplete. There were one or two other primitives which triggered messages which I didn't write down, and now cannot reproduce. 7. Surpising is that insert-file-contents (which gave so much trouble in summer 2016) returned balanced counts. It seems to be mostly the special purpose primitives, those not widely used in Lisp, which are most likely to have strange b-c-f and a-c-f counts. But the case-switching primitives might be troublesome. So might transpose-regions. 8. Possibly these things could be more accurately documented in elisp.info. -- Alan Mackenzie (Nuremberg, Germany).