From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Harald =?UTF-8?Q?J=C3=B6rg?= Newsgroups: gmane.emacs.bugs Subject: bug#43457: 28.0.50; [FEATURE][PATCH] cperl-mode: Add value "PBP" to cperl-set-style Date: Wed, 16 Sep 2020 23:18:20 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F88D2624A8D301B64DF756FC" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24703"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 To: 43457@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 16 23:19:12 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1kIepc-0006J1-4N for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Sep 2020 23:19:12 +0200 Original-Received: from localhost ([::1]:42566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIepb-00049a-6U for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Sep 2020 17:19:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIepU-00049T-34 for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 17:19:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kIepS-0007mB-6v for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 17:19:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kIepR-000487-Tv for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 17:19:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Harald =?UTF-8?Q?J=C3=B6rg?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Sep 2020 21:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 43457 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160029111215836 (code B ref -1); Wed, 16 Sep 2020 21:19:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Sep 2020 21:18:32 +0000 Original-Received: from localhost ([127.0.0.1]:36653 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kIeox-00047M-Rc for submit@debbugs.gnu.org; Wed, 16 Sep 2020 17:18:32 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:37110) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kIeov-00047E-LZ for submit@debbugs.gnu.org; Wed, 16 Sep 2020 17:18:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIeov-00045j-EY for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 17:18:29 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:39479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIeos-0007jk-4d for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 17:18:29 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id EEC1D2400FB for ; Wed, 16 Sep 2020 23:18:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1600291102; bh=NG1D2jitC6bhfeiejhriEDjuVesDrR8dBzVvD7jlFqc=; h=To:From:Subject:Autocrypt:Date:From; b=RIW+8fFpAGckjjpd8WXCEKU/YaFlQ+uQIY0welE1P9tyUq4ZqGwYoOxJ4TqD2gBom DOo5pjKDR9pDiwIaDLWMEnEOFN3KGDkyjxFtd1jXrz+PUnMLkrKpzQcoovhy9D5RBZ Sx4BNpn1Y7ckzX4GsEDUhpTgpmp6frFylDkhvxNnkuAbB6RD1ZYDuNKyfwg6iLdS7P 0yh5a7sByXhEq/Q1x3XcER3+jg5x2hBrok209qPJRbkFrqXQGx8XWvnIo60xbudf4r lRi8r8aGNIJWcMdsAxKX47lguC8eEhfl9rOLHSBoK7jKvDLXjTTAjNQE3tQpKDEoBl Y1xNLk0oXohMg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4BsCcs2qdsz6tmJ for ; Wed, 16 Sep 2020 23:18:21 +0200 (CEST) Autocrypt: addr=haj@posteo.de; keydata= mQINBF0DVrIBEAC7TRlIilBg/5Dx7R2rV4FBDEavbyMT2cS2wWyksh7JA8e17LNmTdakf+Bm u6C2m6+frolteYRlkreoyAg0fj/5tDw/s5dJDw3tM0b+m/pj2HcwTSRpQSEy5lBiCg11E6Mt F9UngCfkGtJzu8PBWXc1RDQVBwRn5MZbpMZZatE8NOq9AA3Yg6sY11Ez3xIvYU2R7a4OSxmc RJV2+dhdQ4oOTBIGQ2urQSU81kyRtkx+/Yh8WefMrk9nF3nzYziLS53euCAXyzklwYmD6Li3 XSu7wYp5fISky9DK6DPFK7h4RXEL4GFAhy31ehrVnNTcGRohM1Dm9BV9dwXkwlaeT3q0X+nE SXVqPDHtv748bXNIg2WVCZ0WgShcA46XVlSE9Fm+w0HI/1m1L4BaMmQ7gyK5dEchbhxohkk0 AqC3hEJ4ULRidrsCoCWGMFKiOIb9rjeC00vhrUkVJDkPWEGLXjhnRQykb6cESko0rPrSDLqX 9YqaNQ6KO9Un6uogE7YnXYg35EXJ8ORdX257IbXNbFVpgM8FFsl48WV3Pl9WNdADhnnOrz3O wzyK58i/BTsnjVX8ghbWkQcPQ2Kprt+4YR2trEi7TM5Uqzzrg0vp7Oe/9KZBxdxCE67thV7h ElW3CHb4q6o31b4cFmLbtFesSy+hnUU4UymgHgi/hvhxioBxIQARAQABtBxIYXJhbGQgSsO2 cmcgPGhhakBwb3N0ZW8uZGU+iQJOBBMBCAA4FiEEIpYEZLQynxF8Q17KN4XzzzqAcpsFAl0D VrICGwMFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQN Content-Language: en-US Received-SPF: pass client-ip=185.67.36.66; envelope-from=haj@posteo.de; helo=mout02.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 15:26:36 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:188181 Archived-At: This is a multi-part message in MIME format. --------------F88D2624A8D301B64DF756FC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit This is not a bug report, but a feature request. If I understand correctly, both go through the same channel. Motivation: cperl-mode offers a command 'cperl-set-style' which sets some customization values for code formatting according to a list of rule sets. The book "Perl Best Practices", known as "PBP" in the Perl community, also defines such a rule set, including the corresponding settings for Emacs (among other editors). The PBP rules are widely accepted for Perl code, so in my opinion it makes sense to make these settings available through 'cperl-set-style'. The attached patch adds the new value "PBP" to the style selection and to the documentation, and also contains a simple formatting test according to these rules. I also added some lines to etc/NEWS, but I'm unsure about the handling of "---" to indicate that the change is not relevant to the manual: There is no texinfo manual for CPerl mode, so maybe "---" should be added before the heading "CPerl Mode"? -- Cheers, haj --------------F88D2624A8D301B64DF756FC Content-Type: text/x-patch; charset=UTF-8; name="0001-cperl-mode-Add-new-value-PBP-for-cperl-set-style.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-cperl-mode-Add-new-value-PBP-for-cperl-set-style.patch" =46rom 14d2c238eafbaf64c29b845cb4de9e4bbac7217f Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Harald=3D20J=3DC3=3DB6rg?=3D Date: Wed, 16 Sep 2020 22:30:01 +0200 Subject: [PATCH] cperl-mode: Add new value "PBP" for 'cperl-set-style' * lisp/progmodes/cperl-mode.el (cperl-style-alist, cperl-set-style): Add indentation style recommended by Damian Conway's book "Perl Best Practices". * test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-indent-styles)= : Add a test to verify indentation and unraveling of conditionals. --- etc/NEWS | 5 +++ lisp/progmodes/cperl-mode.el | 41 +++++++++++++---- .../cperl-indent-styles.pl | 44 +++++++++++++++++++ test/lisp/progmodes/cperl-mode-tests.el | 32 ++++++++++++++ 4 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 test/lisp/progmodes/cperl-mode-resources/cperl-indent= -styles.pl diff --git a/etc/NEWS b/etc/NEWS index 81a4273b0f..8b336a8aa9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1168,6 +1168,11 @@ non-nil, even if protected by 'dbus-ignore-errors'= otherwise. =20 --- *** D-Bus events keep the type information of their arguments. +** CPerl Mode +*** The command 'cperl-set-style' offers the new value "PBP". +This value customizes Emacs to use the style recommended in Damian +Conway's book "Perl Best Practices" for indentation and formatting +of conditionals. =20 =0C * New Modes and Packages in Emacs 28.1 diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index af179e2797..8804e83fce 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -1234,6 +1234,7 @@ cperl-old-style ["Auto fill" auto-fill-mode t]) ("Indent styles..." ["CPerl" (cperl-set-style "CPerl") t] + ["PBP" (cperl-set-style "PBP") t] ["PerlStyle" (cperl-set-style "PerlStyle") t] ["GNU" (cperl-set-style "GNU") t] ["C++" (cperl-set-style "C++") t] @@ -1553,12 +1554,12 @@ cperl-mode `cperl-min-label-indent' Minimal indentation for line that is a label. =20 -Settings for classic indent-styles: K&R BSD=3DC++ GNU PerlStyle=3DWhites= mith - `cperl-indent-level' 5 4 2 4 - `cperl-brace-offset' 0 0 0 0 - `cperl-continued-brace-offset' -5 -4 0 0 - `cperl-label-offset' -5 -4 -2 -4 - `cperl-continued-statement-offset' 5 4 2 4 +Settings for classic indent-styles: K&R BSD=3DC++ GNU PBP PerlStyle=3DWh= itesmith + `cperl-indent-level' 5 4 2 4 4 + `cperl-brace-offset' 0 0 0 0 0 + `cperl-continued-brace-offset' -5 -4 0 0 0 + `cperl-label-offset' -5 -4 -2 -2 -4 + `cperl-continued-statement-offset' 5 4 2 4 4 =20 CPerl knows several indentation styles, and may bulk set the corresponding variables. Use \\[cperl-set-style] to do this. Use @@ -6046,7 +6047,19 @@ cperl-style-examples stop; } =20 -### PerlStyle (=3DCPerl with 4 as indent) 4/0/0/-4/4/t/nil +### PBP (=3DPerl Best Practices) 4/0/0/-4/4/nil/nil +if (foo) { + bar + baz; + label: + { + boon; + } +} +else { + stop; +} +### PerlStyle (=3DCPerl with 4 as indent) 4/0/0/-2/4/t/nil if (foo) { bar baz; @@ -6149,6 +6162,18 @@ cperl-style-alist (cperl-extra-newline-before-brace-multiline . nil) (cperl-merge-trailing-else . t)) =20 + ("PBP" ;; Perl Best Practices by Damian Conway + (cperl-indent-level . 4) + (cperl-brace-offset . 0) + (cperl-continued-brace-offset . 0) + (cperl-label-offset . -2) + (cperl-continued-statement-offset . 4) + (cperl-extra-newline-before-brace . nil) + (cperl-extra-newline-before-brace-multiline . nil) + (cperl-merge-trailing-else . nil) + (cperl-indent-parens-as-block . t) + (cperl-tab-always-indent . t)) + ("PerlStyle" ; CPerl with 4 as indent (cperl-indent-level . 4) (cperl-brace-offset . 0) @@ -6220,7 +6245,7 @@ cperl-set-style "Set CPerl mode variables to use one of several different indentation = styles. The arguments are a string representing the desired style. The list of styles is in `cperl-style-alist', available styles -are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith. +are CPerl, PBP, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith. =20 The current value of style is memorized (unless there is a memorized data already), may be restored by `cperl-set-style-back'. diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles= =2Epl b/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl new file mode 100644 index 0000000000..0832f86828 --- /dev/null +++ b/test/lisp/progmodes/cperl-mode-resources/cperl-indent-styles.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.020; + +# This file contains test input and expected output for the tests in +# cperl-mode-tests.el, cperl-mode-test-indent-exp. The code is +# syntactically valid, but doesn't make much sense. + +# -------- PBP indent: input -------- +for my $foo (@ARGV) +{ +...; +} +# -------- PBP indent: expected output -------- +for my $foo (@ARGV) { + ...; +} +# -------- PBP indent: end -------- + +# -------- PBP uncuddle else: input -------- +{ +if (1 < 2) +{ +say "Seems ok"; +} elsif (1 =3D=3D 2) { +say "Strange things are happening"; +} else { +die "This world is backwards"; +} +} +# -------- PBP uncuddle else: expected output -------- +{ + if (1 < 2) { + say "Seems ok"; + } + elsif (1 =3D=3D 2) { + say "Strange things are happening"; + } + else { + die "This world is backwards"; + } +} +# -------- PBP uncuddle else: end -------- diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmode= s/cperl-mode-tests.el index 2eaf633d17..8e3b73d649 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -172,4 +172,35 @@ cperl-mode-test-indent-exp (setq got (concat "test case " name ":\n" (buffer-string))) (should (equal got expected)))))))) =20 +(ert-deftest cperl-mode-test-indent-styles () + "Verify correct indentation by style \"PBP\". +Perl Best Practices sets some indentation values different from + the defaults, and also wants an \"else\" or \"elsif\" keyword + to align with the \"if\"." + (let ((file (expand-file-name "cperl-indent-styles.pl" + cperl-mode-tests-data-directory))) + (with-temp-buffer + (cperl-set-style "PBP") + (insert-file-contents file) + (goto-char (point-min)) + (while (re-search-forward + (concat "^# ?-+ \\_<\\(?1:.+?\\)\\_>: input ?-+\n" + "\\(?2:\\(?:.*\n\\)+?\\)" + "# ?-+ \\1: expected output ?-+\n" + "\\(?3:\\(?:.*\n\\)+?\\)" + "# ?-+ \\1: end ?-+") + nil t) + (let ((name (match-string 1)) + (code (match-string 2)) + (expected (match-string 3)) + got) + (with-temp-buffer + (insert code) + (cperl-mode) + (indent-region (point-min) (point-max)) ; here we go! + (setq expected (concat "test case " name ":\n" expected)) + (setq got (concat "test case " name ":\n" (buffer-string))) + (should (equal got expected))))) + (cperl-set-style "CPerl")))) + ;;; cperl-mode-tests.el ends here --=20 2.20.1 --------------F88D2624A8D301B64DF756FC--