diff options
| author | Stefan Monnier | 2012-11-08 10:35:32 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2012-11-08 10:35:32 -0500 |
| commit | 79b3e3765638652130d01dc083fdbfa2efc0092c (patch) | |
| tree | 6e5e450536de07a8f1d93aa141738b21b43d643e | |
| parent | 3b11e6ac60fa5c99b97fca3e588947e0b137a250 (diff) | |
| download | emacs-79b3e3765638652130d01dc083fdbfa2efc0092c.tar.gz emacs-79b3e3765638652130d01dc083fdbfa2efc0092c.zip | |
* lisp/progmodes/perl-mode.el (perl-prettify-symbols): New defcustom.
(perl--prettify-symbols-alist): New const.
(perl--font-lock-compose-symbol, perl--font-lock-symbols-keywords): New funs.
(perl-font-lock-keywords-2): Use them.
(perl-electric-noindent-p): New function.
(perl-mode): Use it to set up electric-indent-mode.
(perl-electric-terminator, perl-indent-command): Mark obsolete.
(perl-mode-map): Remove bindings for them.
(perl-imenu-generic-expression, perl-outline-level):
Match functions&packages in column>0.
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/progmodes/perl-mode.el | 90 |
2 files changed, 80 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c040c71cbd4..10cfc97e41f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,17 @@ | |||
| 1 | 2012-11-08 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2012-11-08 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * progmodes/perl-mode.el (perl-prettify-symbols): New defcustom. | ||
| 4 | (perl--prettify-symbols-alist): New const. | ||
| 5 | (perl--font-lock-compose-symbol, perl--font-lock-symbols-keywords): | ||
| 6 | New functions. | ||
| 7 | (perl-font-lock-keywords-2): Use them. | ||
| 8 | (perl-electric-noindent-p): New function. | ||
| 9 | (perl-mode): Use it to set up electric-indent-mode. | ||
| 10 | (perl-electric-terminator, perl-indent-command): Mark obsolete. | ||
| 11 | (perl-mode-map): Remove bindings for them. | ||
| 12 | (perl-imenu-generic-expression, perl-outline-level): | ||
| 13 | Match functions&packages in column>0. | ||
| 14 | |||
| 3 | * env.el (env--substitute-vars-regexp): New const. | 15 | * env.el (env--substitute-vars-regexp): New const. |
| 4 | (substitute-env-vars): Use it. Add `only-defined' arg. | 16 | (substitute-env-vars): Use it. Add `only-defined' arg. |
| 5 | * net/tramp.el (tramp-replace-environment-variables): Use it. | 17 | * net/tramp.el (tramp-replace-environment-variables): Use it. |
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index 3dd9a48bb33..aa8f6b71249 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el | |||
| @@ -119,16 +119,11 @@ | |||
| 119 | 119 | ||
| 120 | (defvar perl-mode-map | 120 | (defvar perl-mode-map |
| 121 | (let ((map (make-sparse-keymap))) | 121 | (let ((map (make-sparse-keymap))) |
| 122 | (define-key map "{" 'perl-electric-terminator) | ||
| 123 | (define-key map "}" 'perl-electric-terminator) | ||
| 124 | (define-key map ";" 'perl-electric-terminator) | ||
| 125 | (define-key map ":" 'perl-electric-terminator) | ||
| 126 | (define-key map "\e\C-a" 'perl-beginning-of-function) | 122 | (define-key map "\e\C-a" 'perl-beginning-of-function) |
| 127 | (define-key map "\e\C-e" 'perl-end-of-function) | 123 | (define-key map "\e\C-e" 'perl-end-of-function) |
| 128 | (define-key map "\e\C-h" 'perl-mark-function) | 124 | (define-key map "\e\C-h" 'perl-mark-function) |
| 129 | (define-key map "\e\C-q" 'perl-indent-exp) | 125 | (define-key map "\e\C-q" 'perl-indent-exp) |
| 130 | (define-key map "\177" 'backward-delete-char-untabify) | 126 | (define-key map "\177" 'backward-delete-char-untabify) |
| 131 | (define-key map "\t" 'perl-indent-command) | ||
| 132 | map) | 127 | map) |
| 133 | "Keymap used in Perl mode.") | 128 | "Keymap used in Perl mode.") |
| 134 | 129 | ||
| @@ -158,16 +153,54 @@ | |||
| 158 | 153 | ||
| 159 | (defvar perl-imenu-generic-expression | 154 | (defvar perl-imenu-generic-expression |
| 160 | '(;; Functions | 155 | '(;; Functions |
| 161 | (nil "^sub\\s-+\\([-A-Za-z0-9+_:]+\\)" 1) | 156 | (nil "^[ \t]*sub\\s-+\\([-A-Za-z0-9+_:]+\\)" 1) |
| 162 | ;;Variables | 157 | ;;Variables |
| 163 | ("Variables" "^\\(?:my\\|our\\)\\s-+\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1) | 158 | ("Variables" "^\\(?:my\\|our\\)\\s-+\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1) |
| 164 | ("Packages" "^package\\s-+\\([-A-Za-z0-9+_:]+\\);" 1) | 159 | ("Packages" "^[ \t]*package\\s-+\\([-A-Za-z0-9+_:]+\\);" 1) |
| 165 | ("Doc sections" "^=head[0-9][ \t]+\\(.*\\)" 1)) | 160 | ("Doc sections" "^=head[0-9][ \t]+\\(.*\\)" 1)) |
| 166 | "Imenu generic expression for Perl mode. See `imenu-generic-expression'.") | 161 | "Imenu generic expression for Perl mode. See `imenu-generic-expression'.") |
| 167 | 162 | ||
| 168 | ;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and | 163 | ;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and |
| 169 | ;; Jim Campbell <jec@murzim.ca.boeing.com>. | 164 | ;; Jim Campbell <jec@murzim.ca.boeing.com>. |
| 170 | 165 | ||
| 166 | (defcustom perl-prettify-symbols t | ||
| 167 | "If non-nil, some symbols will be displayed using Unicode chars." | ||
| 168 | :type 'boolean) | ||
| 169 | |||
| 170 | (defconst perl--prettify-symbols-alist | ||
| 171 | '(;;("andalso" . ?∧) ("orelse" . ?∨) ("as" . ?≡)("not" . ?¬) | ||
| 172 | ;;("div" . ?÷) ("*" . ?×) ("o" . ?○) | ||
| 173 | ("->" . ?→) | ||
| 174 | ("=>" . ?⇒) | ||
| 175 | ;;("<-" . ?←) ("<>" . ?≠) (">=" . ?≥) ("<=" . ?≤) ("..." . ?⋯) | ||
| 176 | ("::" . ?∷) | ||
| 177 | )) | ||
| 178 | |||
| 179 | (defun perl--font-lock-compose-symbol () | ||
| 180 | "Compose a sequence of ascii chars into a symbol. | ||
| 181 | Regexp match data 0 points to the chars." | ||
| 182 | ;; Check that the chars should really be composed into a symbol. | ||
| 183 | (let* ((start (match-beginning 0)) | ||
| 184 | (end (match-end 0)) | ||
| 185 | (syntaxes (if (eq (char-syntax (char-after start)) ?w) | ||
| 186 | '(?w) '(?. ?\\)))) | ||
| 187 | (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes) | ||
| 188 | (memq (char-syntax (or (char-after end) ?\ )) syntaxes) | ||
| 189 | (nth 8 (syntax-ppss))) | ||
| 190 | ;; No composition for you. Let's actually remove any composition | ||
| 191 | ;; we may have added earlier and which is now incorrect. | ||
| 192 | (remove-text-properties start end '(composition)) | ||
| 193 | ;; That's a symbol alright, so add the composition. | ||
| 194 | (compose-region start end (cdr (assoc (match-string 0) | ||
| 195 | perl--prettify-symbols-alist))))) | ||
| 196 | ;; Return nil because we're not adding any face property. | ||
| 197 | nil) | ||
| 198 | |||
| 199 | (defun perl--font-lock-symbols-keywords () | ||
| 200 | (when perl-prettify-symbols | ||
| 201 | `((,(regexp-opt (mapcar 'car perl--prettify-symbols-alist) t) | ||
| 202 | (0 (perl--font-lock-compose-symbol)))))) | ||
| 203 | |||
| 171 | (defconst perl-font-lock-keywords-1 | 204 | (defconst perl-font-lock-keywords-1 |
| 172 | '(;; What is this for? | 205 | '(;; What is this for? |
| 173 | ;;("\\(--- .* ---\\|=== .* ===\\)" . font-lock-string-face) | 206 | ;;("\\(--- .* ---\\|=== .* ===\\)" . font-lock-string-face) |
| @@ -190,32 +223,32 @@ | |||
| 190 | "Subdued level highlighting for Perl mode.") | 223 | "Subdued level highlighting for Perl mode.") |
| 191 | 224 | ||
| 192 | (defconst perl-font-lock-keywords-2 | 225 | (defconst perl-font-lock-keywords-2 |
| 193 | (append perl-font-lock-keywords-1 | 226 | (append |
| 194 | (list | 227 | perl-font-lock-keywords-1 |
| 195 | ;; | 228 | `( ;; Fontify keywords, except those fontified otherwise. |
| 196 | ;; Fontify keywords, except those fontified otherwise. | 229 | ,(concat "\\<" |
| 197 | (concat "\\<" | ||
| 198 | (regexp-opt '("if" "until" "while" "elsif" "else" "unless" | 230 | (regexp-opt '("if" "until" "while" "elsif" "else" "unless" |
| 199 | "do" "dump" "for" "foreach" "exit" "die" | 231 | "do" "dump" "for" "foreach" "exit" "die" |
| 200 | "BEGIN" "END" "return" "exec" "eval") t) | 232 | "BEGIN" "END" "return" "exec" "eval") t) |
| 201 | "\\>") | 233 | "\\>") |
| 202 | ;; | 234 | ;; |
| 203 | ;; Fontify local and my keywords as types. | 235 | ;; Fontify local and my keywords as types. |
| 204 | '("\\<\\(local\\|my\\)\\>" . font-lock-type-face) | 236 | ("\\<\\(local\\|my\\)\\>" . font-lock-type-face) |
| 205 | ;; | 237 | ;; |
| 206 | ;; Fontify function, variable and file name references. | 238 | ;; Fontify function, variable and file name references. |
| 207 | '("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face) | 239 | ("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face) |
| 208 | ;; Additionally underline non-scalar variables. Maybe this is a bad idea. | 240 | ;; Additionally underline non-scalar variables. Maybe this is a bad idea. |
| 209 | ;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face) | 241 | ;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face) |
| 210 | '("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face) | 242 | ("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face) |
| 211 | '("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)" | 243 | ("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)" |
| 212 | (2 (cons font-lock-variable-name-face '(underline)))) | 244 | (2 (cons font-lock-variable-name-face '(underline)))) |
| 213 | '("<\\(\\sw+\\)>" 1 font-lock-constant-face) | 245 | ("<\\(\\sw+\\)>" 1 font-lock-constant-face) |
| 214 | ;; | 246 | ;; |
| 215 | ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'. | 247 | ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'. |
| 216 | '("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?" | 248 | ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?" |
| 217 | (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) | 249 | (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)) |
| 218 | '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face))) | 250 | ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face) |
| 251 | ,@(perl--font-lock-symbols-keywords))) | ||
| 219 | "Gaudy level highlighting for Perl mode.") | 252 | "Gaudy level highlighting for Perl mode.") |
| 220 | 253 | ||
| 221 | (defvar perl-font-lock-keywords perl-font-lock-keywords-1 | 254 | (defvar perl-font-lock-keywords perl-font-lock-keywords-1 |
| @@ -543,8 +576,10 @@ create a new comment." | |||
| 543 | 576 | ||
| 544 | (defun perl-outline-level () | 577 | (defun perl-outline-level () |
| 545 | (cond | 578 | (cond |
| 546 | ((looking-at "package\\s-") 0) | 579 | ((looking-at "[ \t]*\\(package\\)\\s-") |
| 547 | ((looking-at "sub\\s-") 1) | 580 | (- (match-beginning 1) (match-beginning 0))) |
| 581 | ((looking-at "[ \t]*s\\(ub\\)\\s-") | ||
| 582 | (- (match-beginning 1) (match-beginning 0))) | ||
| 548 | ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0)) | 583 | ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0)) |
| 549 | ((looking-at "=cut") 1) | 584 | ((looking-at "=cut") 1) |
| 550 | (t 3))) | 585 | (t 3))) |
| @@ -621,6 +656,11 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'." | |||
| 621 | #'perl-syntax-propertize-function) | 656 | #'perl-syntax-propertize-function) |
| 622 | (add-hook 'syntax-propertize-extend-region-functions | 657 | (add-hook 'syntax-propertize-extend-region-functions |
| 623 | #'syntax-propertize-multiline 'append 'local) | 658 | #'syntax-propertize-multiline 'append 'local) |
| 659 | ;; Electricity. | ||
| 660 | ;; FIXME: setup electric-layout-rules. | ||
| 661 | (set (make-local-variable 'electric-indent-chars) | ||
| 662 | (append '(?\{ ?\} ?\; ?\:) electric-indent-chars)) | ||
| 663 | (add-hook 'electric-indent-functions #'perl-electric-noindent-p nil t) | ||
| 624 | ;; Tell imenu how to handle Perl. | 664 | ;; Tell imenu how to handle Perl. |
| 625 | (set (make-local-variable 'imenu-generic-expression) | 665 | (set (make-local-variable 'imenu-generic-expression) |
| 626 | perl-imenu-generic-expression) | 666 | perl-imenu-generic-expression) |
| @@ -637,7 +677,11 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'." | |||
| 637 | 0 ;Existing comment at bol stays there. | 677 | 0 ;Existing comment at bol stays there. |
| 638 | comment-column)) | 678 | comment-column)) |
| 639 | 679 | ||
| 640 | (defalias 'electric-perl-terminator 'perl-electric-terminator) | 680 | (define-obsolete-function-alias 'electric-perl-terminator |
| 681 | 'perl-electric-terminator "22.1") | ||
| 682 | (defun perl-electric-noindent-p (char) | ||
| 683 | (unless (eolp) 'no-indent)) | ||
| 684 | |||
| 641 | (defun perl-electric-terminator (arg) | 685 | (defun perl-electric-terminator (arg) |
| 642 | "Insert character and maybe adjust indentation. | 686 | "Insert character and maybe adjust indentation. |
| 643 | If at end-of-line, and not in a comment or a quote, correct the indentation." | 687 | If at end-of-line, and not in a comment or a quote, correct the indentation." |
| @@ -661,6 +705,7 @@ If at end-of-line, and not in a comment or a quote, correct the indentation." | |||
| 661 | (perl-indent-line) | 705 | (perl-indent-line) |
| 662 | (delete-char -1)))) | 706 | (delete-char -1)))) |
| 663 | (self-insert-command (prefix-numeric-value arg))) | 707 | (self-insert-command (prefix-numeric-value arg))) |
| 708 | (make-obsolete 'perl-electric-terminator 'electric-indent-mode "24.4") | ||
| 664 | 709 | ||
| 665 | ;; not used anymore, but may be useful someday: | 710 | ;; not used anymore, but may be useful someday: |
| 666 | ;;(defun perl-inside-parens-p () | 711 | ;;(defun perl-inside-parens-p () |
| @@ -744,6 +789,7 @@ following list: | |||
| 744 | (t | 789 | (t |
| 745 | (message "Use backslash to quote # characters.") | 790 | (message "Use backslash to quote # characters.") |
| 746 | (ding t))))))))) | 791 | (ding t))))))))) |
| 792 | (make-obsolete 'perl-indent-command 'indent-according-to-mode "24.4") | ||
| 747 | 793 | ||
| 748 | (defun perl-indent-line (&optional nochange parse-start) | 794 | (defun perl-indent-line (&optional nochange parse-start) |
| 749 | "Indent current line as Perl code. | 795 | "Indent current line as Perl code. |