From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#35771: [PATCH] Customization type of recentf-max-saved-items Date: Fri, 17 May 2019 15:17:57 +0100 Message-ID: <87woipupuy.fsf@tcd.ie> References: <87pnohb79x.fsf@gmail.com> <42941bba-e6b4-4a46-b56f-97ffcfc2117f@default> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="225017"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Dario Gjorgjevski , 35771@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 17 16:19:15 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRdha-000wOu-I6 for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2019 16:19:14 +0200 Original-Received: from localhost ([127.0.0.1]:49302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRdhZ-0005af-Fm for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 May 2019 10:19:13 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRdhT-0005aa-MU for bug-gnu-emacs@gnu.org; Fri, 17 May 2019 10:19:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRdhR-0005Da-Pp for bug-gnu-emacs@gnu.org; Fri, 17 May 2019 10:19:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45175) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRdhO-00059G-6j for bug-gnu-emacs@gnu.org; Fri, 17 May 2019 10:19:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hRdhN-0005l5-VT for bug-gnu-emacs@gnu.org; Fri, 17 May 2019 10:19:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 May 2019 14:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35771 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35771-submit@debbugs.gnu.org id=B35771.155810268722072 (code B ref 35771); Fri, 17 May 2019 14:19:01 +0000 Original-Received: (at 35771) by debbugs.gnu.org; 17 May 2019 14:18:07 +0000 Original-Received: from localhost ([127.0.0.1]:58719 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hRdgU-0005jw-IW for submit@debbugs.gnu.org; Fri, 17 May 2019 10:18:06 -0400 Original-Received: from mail-ed1-f65.google.com ([209.85.208.65]:33052) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hRdgS-0005jT-I1 for 35771@debbugs.gnu.org; Fri, 17 May 2019 10:18:04 -0400 Original-Received: by mail-ed1-f65.google.com with SMTP id n17so10896451edb.0 for <35771@debbugs.gnu.org>; Fri, 17 May 2019 07:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=iC1vEFJcZRt17kwaF1FkM/hmBtyCsOGb2RpDSEmbIUw=; b=NDTEZ6oWSa7sG6zA+4O4go1bcHJnr1Td2kUm5z6nVTpXvywxkjiDO7PaD8VYRV0YSI grqxJKzNw06OzPNeO6HzGZ67HsEdsbE81sdnvFyMXMSfy+l0LEVMTSVuZ+zbh5x7l8T6 rhS2Msk8iBUYDheuCk8j/yqa1rPnu/V4q6RpNQjbvQ19cAb4O1dokaeQ4BAnM/HUggSA Q6GcNXifCWumUA48Y8tIM2jriq1ucUHCrUWKb0jL/xFcypuM/dgHZfuqckz6ZZ+hwXiI mUoqSESK5VyEkJqEEnPdhjNg+P6uILadIhtBVpuZQCZ160LZ3PiPD0X5xjeH+Tmz/JeO cEQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=iC1vEFJcZRt17kwaF1FkM/hmBtyCsOGb2RpDSEmbIUw=; b=bjuIVEjxpBYcf3iy0ykgH9WKVmcvIkBkdpYQkHtnj27fhZB8LOLUQqG4ap9/bYut/h wqDNp5DvKGmcmIKrsRl2pfRAX84SZnWtQurUJSUhDcPw3YZlAgnKKyYHbnlRcfaSCA66 eMZjEWIFY/CAZJm1aUPoI20YjqpaHQwULPyydG50sUoa91rBb6dfgtfdmyEnMlYFJAOx 4F6/Ps0IAg3tMrYYDFORt2HhsoQBShKGhVLXRP3uRwg4Km3TpZPk7S4b3pOyYEK6KeV1 qv2EsJod8D5me1DG8WnGRckZU097Y6NAvjAJnIOpmSQYsVemPJD1QGFgPqZSVHM90oEt r4Qg== X-Gm-Message-State: APjAAAUdGGengdkcWojdFw+FtLoWy3tyZ/uwGACCTZmQZZEQB7VNeX1L EhINbuFv/yF28Lw//jDWINY5jw== X-Google-Smtp-Source: APXvYqyKFNafmgU7ILvSzoKr2TbupNqMiIhzEyFIY59UI6qaiWMtAdE1zKg2p4Wi3S0CQHEBjd2DDw== X-Received: by 2002:a50:ad77:: with SMTP id z52mr58028813edc.174.1558102678936; Fri, 17 May 2019 07:17:58 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:6fa:38d6:1fce:ddb3]) by smtp.gmail.com with ESMTPSA id o3sm1541418ejb.71.2019.05.17.07.17.58 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 17 May 2019 07:17:58 -0700 (PDT) In-Reply-To: <42941bba-e6b4-4a46-b56f-97ffcfc2117f@default> (Drew Adams's message of "Fri, 17 May 2019 06:36:30 -0700 (PDT)") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159452 Archived-At: I don't know whether this has been discussed before, but it seems more suited for emacs-devel or its own bug report, rather than the current one. Drew Adams writes: >> The customization type of recentf-max-saved-items is currently defined >> as integer, which does not include nil in its domain. However, setting >> this variable to nil is supported in the code and also documented. >> >> This patch changes the customization type to explicitly allow for the >> variable to be set to nil through the Customization interface and >> similar. (Please note that I copied the type from save-place-limit in >> order to be consistent.) > > (I'm looking at Emacs 26.2, so apologies if the Emacs 27 > code has already fixed this.) > > The code should also be changed to do one of the following: > > 1. Use `abs' when the variable value is used. I disagree. It does not make sense for a size to be set to a negative number without indication that this is a supported value; it is clearly a user error to do so. Silently interpreting negative numbers as their absolute value further restricts any future modifications to the interpretation of this user option. The programmer should neither be punished for such user errors, nor have to spoon-feed the user. If there is ambiguity as to whether an integral user option can take a negative value, the simplest and IMO best solution is to make the documentation clearer, not to try to outsmart the user. > 2. Use `restricted-sexp' in the defcustom :type, to require > the value to be a non-negative (or possibly a positive?) > integer (or nil). > > I'm guessing there are additional places in Emacs code > where :type 'integer is used but a non-negative integer is > really needed/appropriate. It would be good to improve > those :type specs as well. > > (We might also want to consider adding `natnum' or > `nonnegative-integer', `positive-integer' and > `negative-integer' as possible :type values.) I'd welcome a natnum type. > But it is simple to use `restricted-sexp' to control such > things. And not only would that improve the behavior for > users; it would also, by way of model, encourage users to > use `restricted-sexp' in their own code. I don't see why restricted-sexp should be encouraged. It is far simpler to use and harder to abuse combinations of predefined simple types. Besides, not everyone uses the Customize interface. > Emacs-Lisp code delivered with Emacs is not a great model > in this respect. It rarely uses `restricted-sexp' - at > least it uses it much less than it could/should (IMHO). IMO, that's one of the many things that makes Emacs a great and fun model - the freedom from having to fight a (easily badly specified) type system. Custom types should be as simple and declarative as possible. Anything else should be reserved for exceptional cases. > More generally, the distributed Emacs code is pretty > "lazy" when it comes to providing defcustom definitions - > few :tag descriptions, overly general :type specs, etc. > > E.g., > > (defcustom recentf-max-saved-items 20 > "Maximum number of recently used file names to save. > `nil' means save the whole list. > See command `recentf-save-list'." > :group 'recentf > :type '(choice > (restricted-sexp > :tag "Save no more than this many file names" > :match-alternatives > ((lambda (x) (and (natnump x) (not (zerop x))))) > :value ignore) > (const :tag "Save all file names" nil))) FWIW, my vote is against both trying to overspecify custom types, and using restricted-sexp for such simple examples. If a particular type such as natnum keeps cropping up, TRT is to add that type, not emulate and duplicate it each time as a restricted-sexp. If you agree, and there is no existing bug report for this, please submit one. Thanks, -- Basil