From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Questions regarding char-table-range RANGE arg Date: Fri, 01 Sep 2023 10:34:12 +0300 Message-ID: <8334zycpor.fsf@gnu.org> References: <182a9111-f3e1-e098-97ec-1f5a5269362d@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2473"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Federico Tedin Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 01 09:35:25 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qbyge-0000Pm-Qq for ged-emacs-devel@m.gmane-mx.org; Fri, 01 Sep 2023 09:35:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbyfo-0006Mo-0k; Fri, 01 Sep 2023 03:34:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbyfk-0006MJ-4S for emacs-devel@gnu.org; Fri, 01 Sep 2023 03:34:28 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbyfj-0008Fe-T7; Fri, 01 Sep 2023 03:34:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=YRXrKi0zoGg7X1YfIw/XLzqdBJ1v5rWLV/za4Ub7uoU=; b=q8h1CdUJrAUGw7cGnJBD fct7Ji0nk9yv2JhYMMCVb5IXq876qP8fslfytJFhXgldehR5FoG268tN2h2XJ6b36fP6siVSC98ni +dfxcJgV+pCw3QzWd83AuK1aVpamHRpN1LBV8a//MjizNf4AY7BQwhvNfArSMhrG1CskazwWgj+5z /EUcdcqTPUtuUtx5TpYAF8l1xXJSFd2i6EYnfX0fwT9qCFm0GoJ8+YZBJ/Jhp2zB+GQM8TX7n5Mlm WYewhymC7k0zRUJKE5UYkUmYbJ0aPaSWTdbMPT8cHW1TxuVJx83cJ3e6CFNLHAzAzEUW9PL7bWEsX 23cVif+TE5j5YQ==; In-Reply-To: <182a9111-f3e1-e098-97ec-1f5a5269362d@gmail.com> (message from Federico Tedin on Thu, 31 Aug 2023 23:54:01 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:309730 Archived-At: > Date: Thu, 31 Aug 2023 23:54:01 +0200 > From: Federico Tedin > > Hi everyone, > > I was trying to understand better how char tables work but I got stuck > at the following: > > In the docs for `char-table-range' > (https://www.gnu.org/software/emacs/manual/html_node/elisp/Char_002dTables.html), > it is mentioned > that it is possible to specify (from . to) as the value for RANGE. This > already seemed a bit unexpected for me, as the function > is supposed to retrieve a single value from the char table - how could > it do it for a range, where potentially many different values > could be defined? Char-tables usually include whole ranges of characters with the same value. The implementation of char-tables stores such ranges efficiently, using just one slot instead of a separate slot for every character. This is actually the main reason for having char-tables in Emacs, and the main design goal for their implementation: to allow efficient storage of character properties and quick access to those properties by character code. Thus, querying the value that is in effect for a range of characters makes a lot of sense. > I did some tests: > > (setq tt (make-char-table nil)) > > (set-char-table-range tt (cons 10 20) "foo") > (set-char-table-range tt (cons 21 25) "bar") > [...] > So from my tests it seems like only `from' is considered? Similar to the > case where RANGE is just a character. Basically yes (but see below). > I was hoping someone > with a better understanding of character tables could maybe explain the > behaviour observed above. It is possible it could me just > missinterpreting the documentation (I am trying to keep a more end-user > perspective for this, i.e. not look at the Emacs source code > and only use documentation). I did try looking also into > chartab-tests.el though but could not find more information there. The implementation is in chartab.c, you should look there for the details. What the implementation does is access the value at FROM, and then, if TO is greater than FROM, shrink the range FROM..TO to the largest range of character codes that have the same value as FROM. However, the information about the shrunk range is not returned to the caller of char-table-range. (If this is deemed important, we could add an optional argument to char-table-range which, if non-nil, would cause the function to return a list of, say, (FROM TO VALUE), where TO is the actual value of the shrunk range.) So in the examples you tried: > (char-table-range tt (cons 5 15)) ; includes some "foo" values? >   -> nil ; no Here TO was internally set to 9. > (char-table-range tt (cons 15 22)) ; includes some "foo" and "bar" values? >   -> "foo" ; ok, only the first range was considered Here, TO was internally set to 20. > (char-table-range tt (cons 15 0)) ; what if I set `to' to a nonsensical > value? >   -> "foo" Here TO was ignored, because it is smaller than FROM. > (char-table-range tt (cons 15 99999)) ; or this one >   -> "foo" Here TO was internally set to 20. I hope this answers your questions.