cperl-mode.el: Make sure cperl-file-style is set buffer-local

* lisp/progmodes/cperl-mode.el (cperl-file-style): Add description
what the options actually do.
(cperl-menu): Split the menu entry "Indent styles" into "Default
indent styles" and "Indent styles for current buffer"
(cperl--set-file-style): call `cperl-file-style' instead of
`cperl-set-style'.  This completes the fix for Bug#17948.
(cperl-set-style): Explain when to use `cperl-file-style'.
Use `set-default-toplevel-value' instead of `set'.
(cperl-set-style-back): Use `set-default-toplevel-value' instead
of `set'.
(cperl-file-style): New command to set the file style for the
current buffer.

* etc/NEWS: Announce the new command cperl-file-style.
This commit is contained in:
Harald Jörg 2024-01-08 16:12:19 +01:00
parent d9462e24a9
commit 774c8ec74c
2 changed files with 42 additions and 4 deletions

View file

@ -1116,6 +1116,11 @@ value of 'perl-code' is useful for trailing POD and for AutoSplit
modules, the value 'comment' makes CPerl mode treat trailers as
comment, like Perl mode does.
*** New command 'cperl-file-style'.
This command sets the indentation style for the current buffer. To
change the default style, either use the option with the same name or
use the command cperl-set-style.
*** Commands using the Perl info page are obsolete.
The Perl documentation in info format is no longer distributed with
Perl or on CPAN since more than 10 years. Perl documentation can be

View file

@ -162,6 +162,9 @@ for constructs with multiline if/unless/while/until/for/foreach condition."
(defcustom cperl-file-style nil
"Indentation style to use in cperl-mode.
Setting this option will override options as given in
`cperl-style-alist' for the keyword provided here. If nil, then
the individual options as customized are used.
\"PBP\" is the style recommended in the Book \"Perl Best
Practices\" by Damian Conway. \"CPerl\" is the traditional style
of cperl-mode, and \"PerlStyle\" follows the Perl documentation
@ -1130,7 +1133,7 @@ Unless KEEP, removes the old indentation."
["Fix whitespace on indent" cperl-toggle-construct-fix t]
["Auto-help on Perl constructs" cperl-toggle-autohelp t]
["Auto fill" auto-fill-mode t])
("Indent styles..."
("Default indent styles..."
["CPerl" (cperl-set-style "CPerl") t]
["PBP" (cperl-set-style "PBP") t]
["PerlStyle" (cperl-set-style "PerlStyle") t]
@ -1141,6 +1144,15 @@ Unless KEEP, removes the old indentation."
["Whitesmith" (cperl-set-style "Whitesmith") t]
["Memorize Current" (cperl-set-style "Current") t]
["Memorized" (cperl-set-style-back) cperl-old-style])
("Indent styles for current buffer..."
["CPerl" (cperl-set-style "CPerl") t]
["PBP" (cperl-file-style "PBP") t]
["PerlStyle" (cperl-file-style "PerlStyle") t]
["GNU" (cperl-file-style "GNU") t]
["C++" (cperl-file-style "C++") t]
["K&R" (cperl-file-style "K&R") t]
["BSD" (cperl-file-style "BSD") t]
["Whitesmith" (cperl-file-style "Whitesmith") t])
("Micro-docs"
["Tips" (describe-variable 'cperl-tips) t]
["Problems" (describe-variable 'cperl-problems) t]
@ -1924,7 +1936,8 @@ or as help on variables `cperl-tips', `cperl-problems',
(defun cperl--set-file-style ()
(when cperl-file-style
(cperl-set-style cperl-file-style)))
(cperl-file-style cperl-file-style)))
;; Fix for perldb - make default reasonable
(defun cperl-db ()
@ -6496,6 +6509,10 @@ See examples in `cperl-style-examples'.")
(defun cperl-set-style (style)
"Set CPerl mode variables to use one of several different indentation styles.
This command sets the default values for the variables. It does
not affect buffers visiting files where the style has been set as
a file or directory variable. To change the indentation style of
a buffer, use the command `cperl-file-style' instead.
The arguments are a string representing the desired style.
The list of styles is in `cperl-style-alist', available styles
are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\"
@ -6516,7 +6533,8 @@ side-effect of memorizing only. Examples in `cperl-style-examples'."
(let ((style (cdr (assoc style cperl-style-alist))) setting)
(while style
(setq setting (car style) style (cdr style))
(set (car setting) (cdr setting)))))
(set-default-toplevel-value (car setting) (cdr setting))))
(set-default-toplevel-value 'cperl-file-style style))
(defun cperl-set-style-back ()
"Restore a style memorized by `cperl-set-style'."
@ -6526,7 +6544,22 @@ side-effect of memorizing only. Examples in `cperl-style-examples'."
(while cperl-old-style
(setq setting (car cperl-old-style)
cperl-old-style (cdr cperl-old-style))
(set (car setting) (cdr setting)))))
(set-default-toplevel-value (car setting) (cdr setting)))))
(defun cperl-file-style (style)
"Set the indentation style for the current buffer to STYLE.
The list of styles is in `cperl-style-alist', available styles
are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\"
and \"Whitesmith\"."
(interactive
(list (completing-read "Enter style: " cperl-style-alist nil 'insist)))
(dolist (setting (cdr (assoc style cperl-style-alist)) style)
(let ((option (car setting))
(value (cdr setting)))
(make-variable-buffer-local option)
(set option value)))
(make-variable-buffer-local 'cperl-file-style)
(setq cperl-file-style style))
(declare-function Info-find-node "info"
(filename nodename &optional no-going-back strict-case