From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: akater Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Some improvements for cl-flet, and some more Date: Fri, 24 Sep 2021 15:20:13 +0000 Message-ID: <87tuiac85u.fsf@gmail.com> References: <87bl4zqnqn.fsf@gmail.com> <87mto2gbpu.fsf@gmail.com> <87k0j6gbjg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37234"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , emacs-devel To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 24 17:33:26 2021 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 1mTnCX-0009V7-Uw for ged-emacs-devel@m.gmane-mx.org; Fri, 24 Sep 2021 17:33:26 +0200 Original-Received: from localhost ([::1]:57112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTnCW-00036o-Bc for ged-emacs-devel@m.gmane-mx.org; Fri, 24 Sep 2021 11:33:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTnAu-000291-4P for emacs-devel@gnu.org; Fri, 24 Sep 2021 11:31:44 -0400 Original-Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:44594) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTnAs-0003U6-8F for emacs-devel@gnu.org; Fri, 24 Sep 2021 11:31:43 -0400 Original-Received: by mail-wr1-x435.google.com with SMTP id d6so28550717wrc.11 for ; Fri, 24 Sep 2021 08:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=BeYzUsokIgrZKFLh0J0OV6GRGy39e0r+9kMtYDDo54Y=; b=dekyYt1Bcp/hFW9ZqTWoWYu+wmto/UOCec4+nN37++FhCWgkkReFjYrz0IQRPKaYwO 7w05BbknxOt30Ak4AwjrkxXRHtJOBnDMZZhl+W7d3xqeHLKXw55f0yCQlZ8OM6bqOukh V8lFrNghiG2VND5PjZgpwm4BmtmpC3fsw+U6bqAYF5kdGB7rcDpyyNubMX5RZtx6qTli vaaakMhbI+JhkFNI28zHNSxy7Lz3elLSJ3Kj3RjzFV6UQr+DSPpzwVSguvvg9THxXoKu f99UHWe+uPBfhllgbkJQL1UzLjzlScTX4l9+9A+AKU6UZgnBV1F3PVLPU+esy+YM5ewN 6IgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=BeYzUsokIgrZKFLh0J0OV6GRGy39e0r+9kMtYDDo54Y=; b=LAYHzkipBjtr2n/OaLrviF/EO1kjz18T1hTl7YJy7CeIBIBfmHDlK5GjH+tO5Q4ZH4 AkXHaRivo2Y0kWQ7206KIlFKmJqhN0SmAW+VH+gqlxKTL0QwP9MgP4w1i5CyMX8IOw03 JGV/hTD4TqSYD4MHGPhXKYU16BtXfXuoDeGLMXEvZFLyoydZDkG1EOBgRQ24NkjA8nDo WZYRr1H/B+Jz8GpV46Q/Nn1FmUpiRCcIbwLobPFjllGisCiWC6IskIoRp0vF9T89gyff itEU1COpgm0A6ThEBDm3zuL/eipB75/eWm7tNfYer0rcIb0NeXUUWuzlgCV/RN+jPV8S q7Dw== X-Gm-Message-State: AOAM530uKFttqzONDG7tviE01K6x73MX8zHVbsZyGpOVQ/XWUV7DX1P9 Bde0ynzIjV6fUr3OHGSP6BY= X-Google-Smtp-Source: ABdhPJzdaphb5jDMVZ/pFURbqplOP7weOIQL0REMiD4miCnfhCT65dxSPH6TIjwmcH2JTP7Y7mSvOw== X-Received: by 2002:a1c:7508:: with SMTP id o8mr2878707wmc.104.1632497500687; Fri, 24 Sep 2021 08:31:40 -0700 (PDT) Original-Received: from localhost ([185.247.225.73]) by smtp.googlemail.com with ESMTPSA id b7sm10567740wrm.9.2021.09.24.08.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:31:39 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=nuclearspace@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:275401 Archived-At: --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain I don't feel confindent at all when editing or even reading Emacs indentation code but here you go, this seems to work. --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJLBAEBCgA1FiEEgu5SJRdnQOF34djNsr6xYbHsf0QFAmFN7K0XHG51Y2xlYXJz cGFjZUBnbWFpbC5jb20ACgkQsr6xYbHsf0QtYQ/9HEUVAWVeEnlaeN6kAPI0rOJS Y8ReyUUF3COuSzcsayC8WLCgY+tk5hxsqxl715HCWkiyYn1KGwUgyYqVfiwfEL8Y vdALfNh8H26CDuzDnZFiOQaYehtqGMs6m6SCzTmIWqKulYN5o3DQSE7NasDBXRr2 QEV7r+bxlrNYiRzgPmL7s/3rv60Un8yrmS2DApYqD+D9LE9zMgoGBdJXv2umGj6W JjBZfwCtgT/piTvPpbyvX06D5EYc35yoVxfHvX6fSUq8isaP7hMqkUT60/A8Es5C hN1Hp8lHGaIGSMqrm/9n/sVUlr53HhViBwsGcQ4UAmKSwO706tw4TMmiGvMJPfWL 5yDYgNE+r5gnOHPsIm6R0CBe+tJh1fO9cMhpwLzMyvrLmZajWFkkawqH+r5OhzH7 2F44zFhtkJMY78yZwGH+Lry14fSqjNPHR5zeRroZARgCgIrBz2G4ue4UaTWYP44m L/Vw5qUsYgRAcODhrbXT7mG+r1hVrcEsoaqWZSPlZRgSLGmevglQul9doPw6OPmW NYCYP7g3G6SY75rOQeNySIehM3wg76zLc/Bq5361kR8jEsVdC4CJjE3RBgTn8BKn 0ZghxtHiXrP5GQSKe7oLLz7AiMeV1NXOJJWXnUaHKrLzWrBXdMTooEIOJ/4LSVpW ogiuj/w7EKubG37GHVY= =txoL -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Indent-bodies-of-local-function-definitions-properly.patch Content-Description: Maybe fix cl-flet indentation >From b3105ee7e08ee76f06773ee61ef7bbc264dfefc7 Mon Sep 17 00:00:00 2001 From: akater Date: Fri, 24 Sep 2021 15:04:47 +0000 Subject: [PATCH] Indent bodies of local function definitions properly in elisp-mode * lisp/emacs-lisp/lisp-mode.el (lisp-indent-function): Check for local defforms (lisp--local-defform-body): New auxiliary function --- lisp/emacs-lisp/lisp-mode.el | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index eac3c03cd1..b9bfba60b1 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -29,6 +29,7 @@ ;;; Code: (eval-when-compile (require 'cl-lib)) +(eval-when-compile (require 'subr-x)) (defvar font-lock-comment-face) (defvar font-lock-doc-face) @@ -1105,6 +1106,26 @@ defun calculate-lisp-indent (&optional parse-start) (t normal-indent)))))) +(defun lisp--local-defform-body (state) + "Return non-nil if at local definition body according to STATE. + +STATE is the `parse-partial-sexp' state for current position." + (when-let ((start-of-innermost-containing-list (nth 1 state))) + (let* ((parents (nth 9 state)) second-order-parent + (second-cons-after (cddr parents))) + (while second-cons-after + (when (= start-of-innermost-containing-list + (car second-cons-after)) + (setq second-order-parent (car parents) + ;; Leave the loop. + second-cons-after nil)) + (pop second-cons-after) (pop parents)) + (and second-order-parent + (save-excursion + (goto-char (1+ second-order-parent)) + (memq (read (current-buffer)) + '(cl-flet cl-labels))))))) + (defun lisp-indent-function (indent-point state) "This function is the normal value of the variable `lisp-indent-function'. The function `calculate-lisp-indent' calls this to determine @@ -1138,7 +1159,8 @@ defun lisp-indent-function (indent-point state) (if (and (elt state 2) (not (looking-at "\\sw\\|\\s_"))) ;; car of form doesn't seem to be a symbol - (progn + (if (lisp--local-defform-body state) + (lisp-indent-defform state indent-point) (if (not (> (save-excursion (forward-line 1) (point)) calculate-lisp-indent-last-sexp)) (progn (goto-char calculate-lisp-indent-last-sexp) @@ -1160,7 +1182,9 @@ defun lisp-indent-function (indent-point state) (cond ((or (eq method 'defun) (and (null method) (> (length function) 3) - (string-match "\\`def" function))) + (string-match "\\`def" function)) + ;; Check whether we are in flet or labels. + (lisp--local-defform-body state)) (lisp-indent-defform state indent-point)) ((integerp method) (lisp-indent-specform method state -- 2.32.0 --=-=-=--