summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cperl-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/cperl-mode.el')
-rw-r--r--lisp/progmodes/cperl-mode.el154
1 files changed, 65 insertions, 89 deletions
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 04e4a62c607..2a7bbf01058 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -1,6 +1,6 @@
;;; cperl-mode.el --- Perl code editing commands for Emacs -*- lexical-binding:t -*-
-;; Copyright (C) 1985-1987, 1991-2022 Free Software Foundation, Inc.
+;; Copyright (C) 1985-2022 Free Software Foundation, Inc.
;; Author: Ilya Zakharevich
;; Bob Olson
@@ -28,21 +28,14 @@
;;; Commentary:
-;; This version of the file contains support for the syntax added by
-;; the MooseX::Declare CPAN module, as well as Perl 5.10 keyword
-;; support.
-
;; You can either fine-tune the bells and whistles of this mode or
-;; bulk enable them by putting
-
-;; (setq cperl-hairy t)
+;; bulk enable them by putting this in your Init file:
-;; in your .emacs file. (Emacs rulers do not consider it politically
-;; correct to make whistles enabled by default.)
+;; (setq cperl-hairy t)
;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
-;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
-;; `cperl-praise', `cperl-speed'. <<<<<<
+;; or as help on variables `cperl-tips', `cperl-praise', <<<<<<
+;; `cperl-speed'. <<<<<<
;;
;; Or search for "Short extra-docs" further down in this file for
;; details on how to use `cperl-mode' instead of `perl-mode' and lots
@@ -50,19 +43,18 @@
;; The mode information (on C-h m) provides some customization help.
-;; Faces used now: three faces for first-class and second-class keywords
+;; Faces used: three faces for first-class and second-class keywords
;; and control flow words, one for each: comments, string, labels,
;; functions definitions and packages, arrays, hashes, and variable
-;; definitions. If you do not see all these faces, your font-lock does
-;; not define them, so you need to define them manually.
+;; definitions.
-;; This mode supports font-lock, imenu and mode-compile. In the
-;; hairy version font-lock is on, but you should activate imenu
-;; yourself (note that mode-compile is not standard yet). Well, you
-;; can use imenu from keyboard anyway (M-x imenu), but it is better
-;; to bind it like that:
+;; This mode supports imenu. You can use imenu from the keyboard
+;; (M-g i), but you might prefer binding it like this:
+;;
+;; (define-key global-map [M-S-down-mouse-3] #'imenu)
-;; (define-key global-map [M-S-down-mouse-3] 'imenu)
+;; This version supports the syntax added by the MooseX::Declare CPAN
+;; module, as well as Perl 5.10 keyword support.
;;; Code:
@@ -98,7 +90,7 @@
(let (answer)
(while list
(or answer
- (if (or (x-color-defined-p (car list))
+ (if (or (color-defined-p (car list))
(null (cdr list)))
(setq answer (car list))))
(setq list (cdr list)))
@@ -553,6 +545,20 @@ This way enabling/disabling of menu items is more correct."
:type 'boolean
:group 'cperl-speed)
+(defcustom cperl-file-style nil
+ "Indentation style to use in cperl-mode."
+ :type '(choice (const "CPerl")
+ (const "PBP")
+ (const "PerlStyle")
+ (const "GNU")
+ (const "C++")
+ (const "K&R")
+ (const "BSD")
+ (const "Whitesmith")
+ (const :tag "Default" nil))
+ :version "29.1")
+;;;###autoload(put 'cperl-file-style 'safe-local-variable 'stringp)
+
(defcustom cperl-ps-print-face-properties
'((font-lock-keyword-face nil nil bold shadow)
(font-lock-variable-name-face nil nil bold)
@@ -872,8 +878,9 @@ In regular expressions (including character classes):
(and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
(setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
-(defun cperl-putback-char (c) ; Emacs 19
- (push c unread-command-events)) ; Avoid undefined warning
+(defun cperl-putback-char (c)
+ (declare (obsolete nil "29.1"))
+ (push c unread-command-events))
(defsubst cperl-put-do-not-fontify (from to &optional post)
;; If POST, do not do it with postponed fontification
@@ -1014,15 +1021,9 @@ Unless KEEP, removes the old indentation."
(define-key map [(control ?c) (control ?h) ?v]
;;(concat (char-to-string help-char) "v") ; does not work
'cperl-get-help))
- (substitute-key-definition
- 'indent-sexp 'cperl-indent-exp
- map global-map)
- (substitute-key-definition
- 'indent-region 'cperl-indent-region
- map global-map)
- (substitute-key-definition
- 'indent-for-comment 'cperl-indent-for-comment
- map global-map)
+ (define-key map [remap indent-sexp] #'cperl-indent-exp)
+ (define-key map [remap indent-region] #'cperl-indent-region)
+ (define-key map [remap indent-for-comment] #'cperl-indent-for-comment)
map)
"Keymap used in CPerl mode.")
@@ -1078,7 +1079,7 @@ Unless KEEP, removes the old indentation."
["Debugger" cperl-db t]
"----"
("Tools"
- ["Imenu" imenu (fboundp 'imenu)]
+ ["Imenu" imenu]
["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
"----"
["Ispell PODs" cperl-pod-spell
@@ -1110,8 +1111,7 @@ Unless KEEP, removes the old indentation."
(get-text-property (point) 'syntax-type))
'(here-doc pod))]
"----"
- ["CPerl pretty print (experimental)" cperl-ps-print
- (fboundp 'ps-extend-face-list)]
+ ["CPerl pretty print (experimental)" cperl-ps-print]
"----"
["Syntaxify region" cperl-find-pods-heres-region
(use-region-p)]
@@ -1124,15 +1124,6 @@ Unless KEEP, removes the old indentation."
["Class Hierarchy from TAGS" cperl-tags-hier-init t]
;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
("Tags"
- ;; ["Create tags for current file" cperl-etags t]
- ;; ["Add tags for current file" (cperl-etags t) t]
- ;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
- ;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
- ;; ["Create tags for Perl files in (sub)directories"
- ;; (cperl-etags nil 'recursive) t]
- ;; ["Add tags for Perl files in (sub)directories"
- ;; (cperl-etags t 'recursive) t])
- ;; ;;? cperl-write-tags (&optional file erase recurse dir inbuffer)
["Create tags for current file" (cperl-write-tags nil t) t]
["Add tags for current file" (cperl-write-tags) t]
["Create tags for Perl files in directory"
@@ -1145,6 +1136,8 @@ Unless KEEP, removes the old indentation."
(cperl-write-tags nil nil t t) t]))
("Perl docs"
["Define word at point" imenu-go-find-at-position
+ ;; This is from imenu-go.el. I can't find it on any ELPA
+ ;; archive, so I'm not sure if it's still in use or not.
(fboundp 'imenu-go-find-at-position)]
["Help on function" cperl-info-on-command t]
["Help on function at point" cperl-info-on-current-command t]
@@ -1309,7 +1302,7 @@ name, and one for the discovery of a following BLOCK.")
,cperl--ws+-rx
(group-n 2 ,cperl--normal-identifier-rx))
"A regular expression to detect a subroutine start.
-Contains three groups: One one to distinguish lexical from
+Contains three groups: One to distinguish lexical from
\"normal\" subroutines, for the keyword \"sub\", and one for the
subroutine name.")
@@ -1661,9 +1654,11 @@ Settings for classic indent-styles: K&R BSD=C++ GNU PBP PerlStyle=Whitesmith
`cperl-continued-statement-offset' 5 4 2 4 4
CPerl knows several indentation styles, and may bulk set the
-corresponding variables. Use \\[cperl-set-style] to do this. Use
-\\[cperl-set-style-back] to restore the memorized preexisting values
-\(both available from menu). See examples in `cperl-style-examples'.
+corresponding variables. Use \\[cperl-set-style] to do this or
+set the `cperl-file-style' user option. Use
+\\[cperl-set-style-back] to restore the memorized preexisting
+values \(both available from menu). See examples in
+`cperl-style-examples'.
Part of the indentation style is how different parts of if/elsif/else
statements are broken into lines; in CPerl, this is reflected on how
@@ -1796,8 +1791,15 @@ or as help on variables `cperl-tips', `cperl-problems',
(when (and cperl-pod-here-scan
(not cperl-syntaxify-by-font-lock))
(cperl-find-pods-heres))
+ (when cperl-file-style
+ (cperl-set-style cperl-file-style))
+ (add-hook 'hack-local-variables-hook #'cperl--set-file-style nil t)
;; Setup Flymake
(add-hook 'flymake-diagnostic-functions #'perl-flymake nil t))
+
+(defun cperl--set-file-style ()
+ (when cperl-file-style
+ (cperl-set-style cperl-file-style)))
;; Fix for perldb - make default reasonable
(defun cperl-db ()
@@ -1871,25 +1873,6 @@ or as help on variables `cperl-tips', `cperl-problems',
(cperl-make-indent comment-column 1) ; Indent min 1
c)))))
-;;(defun cperl-comment-indent-fallback ()
-;; "Is called if the standard comment-search procedure fails.
-;;Point is at start of real comment."
-;; (let ((c (current-column)) target cnt prevc)
-;; (if (= c comment-column) nil
-;; (setq cnt (skip-chars-backward " \t"))
-;; (setq target (max (1+ (setq prevc
-;; (current-column))) ; Else indent at comment column
-;; comment-column))
-;; (if (= c comment-column) nil
-;; (delete-backward-char cnt)
-;; (while (< prevc target)
-;; (insert "\t")
-;; (setq prevc (current-column)))
-;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
-;; (while (< prevc target)
-;; (insert " ")
-;; (setq prevc (current-column)))))))
-
(defun cperl-indent-for-comment ()
"Substitute for `indent-for-comment' in CPerl."
(interactive)
@@ -2161,7 +2144,7 @@ to nil."
(delete-char -1)
(delete-char 1))))
(if delete
- (cperl-putback-char cperl-del-back-ch))
+ (push cperl-del-back-ch unread-command-events))
(if cperl-message-electric-keyword
(message "Precede char by C-q to avoid expansion"))))))
@@ -2235,7 +2218,7 @@ to nil."
(end-of-line)
(setq really-delete t)))
(if (and delete really-delete)
- (cperl-putback-char cperl-del-back-ch))))))
+ (push cperl-del-back-ch unread-command-events))))))
(defun cperl-electric-else ()
"Insert a construction appropriate after a keyword.
@@ -2272,7 +2255,7 @@ to nil."
(cperl-indent-line)
(forward-line -1)
(cperl-indent-line)
- (cperl-putback-char cperl-del-back-ch)
+ (push cperl-del-back-ch unread-command-events)
(setq this-command 'cperl-electric-else)
(if cperl-message-electric-keyword
(message "Precede char by C-q to avoid expansion"))))))
@@ -3835,7 +3818,7 @@ recursive calls in starting lines of here-documents."
"\\<" cperl-sub-regexp "\\>" ; sub with proto/attr
"\\("
cperl-white-and-comment-rex
- (rx (group (eval cperl--normal-identifier-rx)))
+ (rx (opt (group (eval cperl--normal-identifier-rx))))
"\\)"
"\\("
cperl-maybe-white-and-comment-rex
@@ -5946,7 +5929,7 @@ default function."
(eval cperl--basic-identifier-rx)))
(0+ blank) "(")
;; '("\\<for\\(each\\)?\\([ \t]+\\(state\\|my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
- 4 font-lock-variable-name-face)
+ 1 font-lock-variable-name-face)
;; Avoid $!, and s!!, qq!! etc. when not fontifying syntactically
'("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
'("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
@@ -6013,7 +5996,7 @@ default function."
cperl-font-lock-keywords-2 (append
t-font-lock-keywords-1
cperl-font-lock-keywords-1)))
- (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
+ (cperl-ps-print-init)
(setq cperl-faces-init t))
(error (message "cperl-init-faces (ignored): %s" errs))))
@@ -6314,7 +6297,7 @@ else
)
("Current"))
"List of variables to set to get a particular indentation style.
-Should be used via `cperl-set-style' or via Perl menu.
+Should be used via `cperl-set-style', `cperl-file-style' or via Perl menu.
See examples in `cperl-style-examples'.")
@@ -6360,7 +6343,8 @@ side-effect of memorizing only. Examples in `cperl-style-examples'."
(eval '(mode-compile)))) ; Avoid a warning
(declare-function Info-find-node "info"
- (filename nodename &optional no-going-back strict-case))
+ (filename nodename &optional no-going-back strict-case
+ noerror))
(defun cperl-info-buffer (type)
;; Return buffer with documentation. Creates if missing.
@@ -7057,9 +7041,7 @@ One may build such TAGS files from CPerl mode menu."
(error "No items found"))
(setq update
;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
- (if (if (fboundp 'display-popup-menus-p)
- (display-popup-menus-p)
- window-system)
+ (if (display-popup-menus-p)
(x-popup-menu t (nth 2 cperl-hierarchy))
(require 'tmm)
(tmm-prompt (nth 2 cperl-hierarchy))))
@@ -7140,13 +7122,6 @@ One may build such TAGS files from CPerl mode menu."
(sort root-packages (default-value 'imenu-sort-function)))
root-packages))))
-;;(x-popup-menu t
-;; '(keymap "Name1"
-;; ("Ret1" "aa")
-;; ("Head1" "ab"
-;; keymap "Name2"
-;; ("Tail1" "x") ("Tail2" "y"))))
-
(defun cperl-list-fold (list name limit)
(let (list1 list2 elt1 (num 0))
(if (<= (length list) limit) list
@@ -8399,10 +8374,12 @@ the appropriate statement modifier."
(interactive)
(cperl-perldoc (cperl-word-at-point)))
-(defcustom pod2man-program "pod2man"
+(define-obsolete-variable-alias 'pod2man-program 'cperl-pod2man-program "29.1")
+(defcustom cperl-pod2man-program "pod2man"
"File name for `pod2man'."
:type 'file
- :group 'cperl)
+ :group 'cperl
+ :version "29.1")
;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
(defun cperl-pod-to-manpage ()
@@ -8421,7 +8398,6 @@ the appropriate statement modifier."
(format (cperl-pod2man-build-command) pod2man-args))
'Man-bgproc-sentinel)))))
-;; Updated version by him too
(defun cperl-build-manpage ()
"Create a virtual manpage in Emacs from the POD in the file."
(interactive)