aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Jörg2024-01-08 16:12:19 +0100
committerHarald Jörg2024-01-08 16:12:19 +0100
commit774c8ec74c98d69d56b2511a613145f2b69fb2eb (patch)
tree5e65d09ccc915ad56c3a126ab5ca0017cc76b1cb
parentd9462e24a967e32d550ee886b5150f0cc78358f6 (diff)
downloademacs-774c8ec74c98d69d56b2511a613145f2b69fb2eb.tar.gz
emacs-774c8ec74c98d69d56b2511a613145f2b69fb2eb.zip
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.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/progmodes/cperl-mode.el41
2 files changed, 42 insertions, 4 deletions
diff --git a/etc/NEWS b/etc/NEWS
index c3d777b971f..f4d008ee2d6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1116,6 +1116,11 @@ value of 'perl-code' is useful for trailing POD and for AutoSplit
1116modules, the value 'comment' makes CPerl mode treat trailers as 1116modules, the value 'comment' makes CPerl mode treat trailers as
1117comment, like Perl mode does. 1117comment, like Perl mode does.
1118 1118
1119*** New command 'cperl-file-style'.
1120This command sets the indentation style for the current buffer. To
1121change the default style, either use the option with the same name or
1122use the command cperl-set-style.
1123
1119*** Commands using the Perl info page are obsolete. 1124*** Commands using the Perl info page are obsolete.
1120The Perl documentation in info format is no longer distributed with 1125The Perl documentation in info format is no longer distributed with
1121Perl or on CPAN since more than 10 years. Perl documentation can be 1126Perl or on CPAN since more than 10 years. Perl documentation can be
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 9f7f29b8182..5e435f7133e 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -162,6 +162,9 @@ for constructs with multiline if/unless/while/until/for/foreach condition."
162 162
163(defcustom cperl-file-style nil 163(defcustom cperl-file-style nil
164 "Indentation style to use in cperl-mode. 164 "Indentation style to use in cperl-mode.
165Setting this option will override options as given in
166`cperl-style-alist' for the keyword provided here. If nil, then
167the individual options as customized are used.
165\"PBP\" is the style recommended in the Book \"Perl Best 168\"PBP\" is the style recommended in the Book \"Perl Best
166Practices\" by Damian Conway. \"CPerl\" is the traditional style 169Practices\" by Damian Conway. \"CPerl\" is the traditional style
167of cperl-mode, and \"PerlStyle\" follows the Perl documentation 170of cperl-mode, and \"PerlStyle\" follows the Perl documentation
@@ -1130,7 +1133,7 @@ Unless KEEP, removes the old indentation."
1130 ["Fix whitespace on indent" cperl-toggle-construct-fix t] 1133 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
1131 ["Auto-help on Perl constructs" cperl-toggle-autohelp t] 1134 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
1132 ["Auto fill" auto-fill-mode t]) 1135 ["Auto fill" auto-fill-mode t])
1133 ("Indent styles..." 1136 ("Default indent styles..."
1134 ["CPerl" (cperl-set-style "CPerl") t] 1137 ["CPerl" (cperl-set-style "CPerl") t]
1135 ["PBP" (cperl-set-style "PBP") t] 1138 ["PBP" (cperl-set-style "PBP") t]
1136 ["PerlStyle" (cperl-set-style "PerlStyle") t] 1139 ["PerlStyle" (cperl-set-style "PerlStyle") t]
@@ -1141,6 +1144,15 @@ Unless KEEP, removes the old indentation."
1141 ["Whitesmith" (cperl-set-style "Whitesmith") t] 1144 ["Whitesmith" (cperl-set-style "Whitesmith") t]
1142 ["Memorize Current" (cperl-set-style "Current") t] 1145 ["Memorize Current" (cperl-set-style "Current") t]
1143 ["Memorized" (cperl-set-style-back) cperl-old-style]) 1146 ["Memorized" (cperl-set-style-back) cperl-old-style])
1147 ("Indent styles for current buffer..."
1148 ["CPerl" (cperl-set-style "CPerl") t]
1149 ["PBP" (cperl-file-style "PBP") t]
1150 ["PerlStyle" (cperl-file-style "PerlStyle") t]
1151 ["GNU" (cperl-file-style "GNU") t]
1152 ["C++" (cperl-file-style "C++") t]
1153 ["K&R" (cperl-file-style "K&R") t]
1154 ["BSD" (cperl-file-style "BSD") t]
1155 ["Whitesmith" (cperl-file-style "Whitesmith") t])
1144 ("Micro-docs" 1156 ("Micro-docs"
1145 ["Tips" (describe-variable 'cperl-tips) t] 1157 ["Tips" (describe-variable 'cperl-tips) t]
1146 ["Problems" (describe-variable 'cperl-problems) t] 1158 ["Problems" (describe-variable 'cperl-problems) t]
@@ -1924,7 +1936,8 @@ or as help on variables `cperl-tips', `cperl-problems',
1924 1936
1925(defun cperl--set-file-style () 1937(defun cperl--set-file-style ()
1926 (when cperl-file-style 1938 (when cperl-file-style
1927 (cperl-set-style cperl-file-style))) 1939 (cperl-file-style cperl-file-style)))
1940
1928 1941
1929;; Fix for perldb - make default reasonable 1942;; Fix for perldb - make default reasonable
1930(defun cperl-db () 1943(defun cperl-db ()
@@ -6496,6 +6509,10 @@ See examples in `cperl-style-examples'.")
6496 6509
6497(defun cperl-set-style (style) 6510(defun cperl-set-style (style)
6498 "Set CPerl mode variables to use one of several different indentation styles. 6511 "Set CPerl mode variables to use one of several different indentation styles.
6512This command sets the default values for the variables. It does
6513not affect buffers visiting files where the style has been set as
6514a file or directory variable. To change the indentation style of
6515a buffer, use the command `cperl-file-style' instead.
6499The arguments are a string representing the desired style. 6516The arguments are a string representing the desired style.
6500The list of styles is in `cperl-style-alist', available styles 6517The list of styles is in `cperl-style-alist', available styles
6501are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\" 6518are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\"
@@ -6516,7 +6533,8 @@ side-effect of memorizing only. Examples in `cperl-style-examples'."
6516 (let ((style (cdr (assoc style cperl-style-alist))) setting) 6533 (let ((style (cdr (assoc style cperl-style-alist))) setting)
6517 (while style 6534 (while style
6518 (setq setting (car style) style (cdr style)) 6535 (setq setting (car style) style (cdr style))
6519 (set (car setting) (cdr setting))))) 6536 (set-default-toplevel-value (car setting) (cdr setting))))
6537 (set-default-toplevel-value 'cperl-file-style style))
6520 6538
6521(defun cperl-set-style-back () 6539(defun cperl-set-style-back ()
6522 "Restore a style memorized by `cperl-set-style'." 6540 "Restore a style memorized by `cperl-set-style'."
@@ -6526,7 +6544,22 @@ side-effect of memorizing only. Examples in `cperl-style-examples'."
6526 (while cperl-old-style 6544 (while cperl-old-style
6527 (setq setting (car cperl-old-style) 6545 (setq setting (car cperl-old-style)
6528 cperl-old-style (cdr cperl-old-style)) 6546 cperl-old-style (cdr cperl-old-style))
6529 (set (car setting) (cdr setting))))) 6547 (set-default-toplevel-value (car setting) (cdr setting)))))
6548
6549(defun cperl-file-style (style)
6550 "Set the indentation style for the current buffer to STYLE.
6551The list of styles is in `cperl-style-alist', available styles
6552are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\"
6553and \"Whitesmith\"."
6554 (interactive
6555 (list (completing-read "Enter style: " cperl-style-alist nil 'insist)))
6556 (dolist (setting (cdr (assoc style cperl-style-alist)) style)
6557 (let ((option (car setting))
6558 (value (cdr setting)))
6559 (make-variable-buffer-local option)
6560 (set option value)))
6561 (make-variable-buffer-local 'cperl-file-style)
6562 (setq cperl-file-style style))
6530 6563
6531(declare-function Info-find-node "info" 6564(declare-function Info-find-node "info"
6532 (filename nodename &optional no-going-back strict-case 6565 (filename nodename &optional no-going-back strict-case