Mercurial > emacs
comparison lisp/progmodes/cperl-mode.el @ 101002:3b3c7e10cd97
Replace last-command-char with last-command-event.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 09 Jan 2009 04:15:52 +0000 |
parents | a9dc0e7c3f2b |
children | 0685234e527d |
comparison
equal
deleted
inserted
replaced
101001:14b421290b2f | 101002:3b3c7e10cd97 |
---|---|
2035 ;; Need to insert a matching pair | 2035 ;; Need to insert a matching pair |
2036 (progn | 2036 (progn |
2037 (save-excursion | 2037 (save-excursion |
2038 (setq insertpos (point-marker)) | 2038 (setq insertpos (point-marker)) |
2039 (goto-char other-end) | 2039 (goto-char other-end) |
2040 (setq last-command-char ?\{) | 2040 (setq last-command-event ?\{) |
2041 (cperl-electric-lbrace arg insertpos)) | 2041 (cperl-electric-lbrace arg insertpos)) |
2042 (forward-char 1)) | 2042 (forward-char 1)) |
2043 ;; Check whether we close something "usual" with `}' | 2043 ;; Check whether we close something "usual" with `}' |
2044 (if (and (eq last-command-char ?\}) | 2044 (if (and (eq last-command-event ?\}) |
2045 (not | 2045 (not |
2046 (condition-case nil | 2046 (condition-case nil |
2047 (save-excursion | 2047 (save-excursion |
2048 (up-list (- (prefix-numeric-value arg))) | 2048 (up-list (- (prefix-numeric-value arg))) |
2049 ;;(cperl-after-block-p (point-min)) | 2049 ;;(cperl-after-block-p (point-min)) |
2057 (eolp) | 2057 (eolp) |
2058 (or (and (null only-before) | 2058 (or (and (null only-before) |
2059 (save-excursion | 2059 (save-excursion |
2060 (skip-chars-backward " \t") | 2060 (skip-chars-backward " \t") |
2061 (bolp))) | 2061 (bolp))) |
2062 (and (eq last-command-char ?\{) ; Do not insert newline | 2062 (and (eq last-command-event ?\{) ; Do not insert newline |
2063 ;; if after ")" and `cperl-extra-newline-before-brace' | 2063 ;; if after ")" and `cperl-extra-newline-before-brace' |
2064 ;; is nil, do not insert extra newline. | 2064 ;; is nil, do not insert extra newline. |
2065 (not cperl-extra-newline-before-brace) | 2065 (not cperl-extra-newline-before-brace) |
2066 (save-excursion | 2066 (save-excursion |
2067 (skip-chars-backward " \t") | 2067 (skip-chars-backward " \t") |
2078 (newline) | 2078 (newline) |
2079 (cperl-indent-line))) | 2079 (cperl-indent-line))) |
2080 (save-excursion | 2080 (save-excursion |
2081 (if insertpos (progn (goto-char insertpos) | 2081 (if insertpos (progn (goto-char insertpos) |
2082 (search-forward (make-string | 2082 (search-forward (make-string |
2083 1 last-command-char)) | 2083 1 last-command-event)) |
2084 (setq insertpos (1- (point))))) | 2084 (setq insertpos (1- (point))))) |
2085 (delete-char -1)))) | 2085 (delete-char -1)))) |
2086 (if insertpos | 2086 (if insertpos |
2087 (save-excursion | 2087 (save-excursion |
2088 (goto-char insertpos) | 2088 (goto-char insertpos) |
2117 (cperl-after-expr-p nil "{;)")) | 2117 (cperl-after-expr-p nil "{;)")) |
2118 nil | 2118 nil |
2119 (setq cperl-auto-newline nil)) | 2119 (setq cperl-auto-newline nil)) |
2120 (cperl-electric-brace arg) | 2120 (cperl-electric-brace arg) |
2121 (and (cperl-val 'cperl-electric-parens) | 2121 (and (cperl-val 'cperl-electric-parens) |
2122 (eq last-command-char ?{) | 2122 (eq last-command-event ?{) |
2123 (memq last-command-char | 2123 (memq last-command-event |
2124 (append cperl-electric-parens-string nil)) | 2124 (append cperl-electric-parens-string nil)) |
2125 (or (if other-end (goto-char (marker-position other-end))) | 2125 (or (if other-end (goto-char (marker-position other-end))) |
2126 t) | 2126 t) |
2127 (setq last-command-char ?} pos (point)) | 2127 (setq last-command-event ?} pos (point)) |
2128 (progn (cperl-electric-brace arg t) | 2128 (progn (cperl-electric-brace arg t) |
2129 (goto-char pos))))) | 2129 (goto-char pos))))) |
2130 | 2130 |
2131 (defun cperl-electric-paren (arg) | 2131 (defun cperl-electric-paren (arg) |
2132 "Insert an opening parenthesis or a matching pair of parentheses. | 2132 "Insert an opening parenthesis or a matching pair of parentheses. |
2139 (save-excursion | 2139 (save-excursion |
2140 (goto-char (mark)) | 2140 (goto-char (mark)) |
2141 (point-marker)) | 2141 (point-marker)) |
2142 nil))) | 2142 nil))) |
2143 (if (and (cperl-val 'cperl-electric-parens) | 2143 (if (and (cperl-val 'cperl-electric-parens) |
2144 (memq last-command-char | 2144 (memq last-command-event |
2145 (append cperl-electric-parens-string nil)) | 2145 (append cperl-electric-parens-string nil)) |
2146 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)) | 2146 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)) |
2147 ;;(not (save-excursion (search-backward "#" beg t))) | 2147 ;;(not (save-excursion (search-backward "#" beg t))) |
2148 (if (eq last-command-char ?<) | 2148 (if (eq last-command-event ?<) |
2149 (progn | 2149 (progn |
2150 (and abbrev-mode ; later it is too late, may be after `for' | 2150 (and abbrev-mode ; later it is too late, may be after `for' |
2151 (expand-abbrev)) | 2151 (expand-abbrev)) |
2152 (cperl-after-expr-p nil "{;(,:=")) | 2152 (cperl-after-expr-p nil "{;(,:=")) |
2153 1)) | 2153 1)) |
2154 (progn | 2154 (progn |
2155 (self-insert-command (prefix-numeric-value arg)) | 2155 (self-insert-command (prefix-numeric-value arg)) |
2156 (if other-end (goto-char (marker-position other-end))) | 2156 (if other-end (goto-char (marker-position other-end))) |
2157 (insert (make-string | 2157 (insert (make-string |
2158 (prefix-numeric-value arg) | 2158 (prefix-numeric-value arg) |
2159 (cdr (assoc last-command-char '((?{ .?}) | 2159 (cdr (assoc last-command-event '((?{ .?}) |
2160 (?[ . ?]) | 2160 (?[ . ?]) |
2161 (?( . ?)) | 2161 (?( . ?)) |
2162 (?< . ?>)))))) | 2162 (?< . ?>)))))) |
2163 (forward-char (- (prefix-numeric-value arg)))) | 2163 (forward-char (- (prefix-numeric-value arg)))) |
2164 (self-insert-command (prefix-numeric-value arg))))) | 2164 (self-insert-command (prefix-numeric-value arg))))) |
2169 Affected by `cperl-electric-parens'." | 2169 Affected by `cperl-electric-parens'." |
2170 (interactive "P") | 2170 (interactive "P") |
2171 (let ((beg (save-excursion (beginning-of-line) (point))) | 2171 (let ((beg (save-excursion (beginning-of-line) (point))) |
2172 (other-end (if (and cperl-electric-parens-mark | 2172 (other-end (if (and cperl-electric-parens-mark |
2173 (cperl-val 'cperl-electric-parens) | 2173 (cperl-val 'cperl-electric-parens) |
2174 (memq last-command-char | 2174 (memq last-command-event |
2175 (append cperl-electric-parens-string nil)) | 2175 (append cperl-electric-parens-string nil)) |
2176 (cperl-mark-active) | 2176 (cperl-mark-active) |
2177 (< (mark) (point))) | 2177 (< (mark) (point))) |
2178 (mark) | 2178 (mark) |
2179 nil)) | 2179 nil)) |
2180 p) | 2180 p) |
2181 (if (and other-end | 2181 (if (and other-end |
2182 (cperl-val 'cperl-electric-parens) | 2182 (cperl-val 'cperl-electric-parens) |
2183 (memq last-command-char '( ?\) ?\] ?\} ?\> )) | 2183 (memq last-command-event '( ?\) ?\] ?\} ?\> )) |
2184 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)) | 2184 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)) |
2185 ;;(not (save-excursion (search-backward "#" beg t))) | 2185 ;;(not (save-excursion (search-backward "#" beg t))) |
2186 ) | 2186 ) |
2187 (progn | 2187 (progn |
2188 (self-insert-command (prefix-numeric-value arg)) | 2188 (self-insert-command (prefix-numeric-value arg)) |
2189 (setq p (point)) | 2189 (setq p (point)) |
2190 (if other-end (goto-char other-end)) | 2190 (if other-end (goto-char other-end)) |
2191 (insert (make-string | 2191 (insert (make-string |
2192 (prefix-numeric-value arg) | 2192 (prefix-numeric-value arg) |
2193 (cdr (assoc last-command-char '((?\} . ?\{) | 2193 (cdr (assoc last-command-event '((?\} . ?\{) |
2194 (?\] . ?\[) | 2194 (?\] . ?\[) |
2195 (?\) . ?\() | 2195 (?\) . ?\() |
2196 (?\> . ?\<)))))) | 2196 (?\> . ?\<)))))) |
2197 (goto-char (1+ p))) | 2197 (goto-char (1+ p))) |
2198 (self-insert-command (prefix-numeric-value arg))))) | 2198 (self-insert-command (prefix-numeric-value arg))))) |
2200 (defun cperl-electric-keyword () | 2200 (defun cperl-electric-keyword () |
2201 "Insert a construction appropriate after a keyword. | 2201 "Insert a construction appropriate after a keyword. |
2202 Help message may be switched off by setting `cperl-message-electric-keyword' | 2202 Help message may be switched off by setting `cperl-message-electric-keyword' |
2203 to nil." | 2203 to nil." |
2204 (let ((beg (save-excursion (beginning-of-line) (point))) | 2204 (let ((beg (save-excursion (beginning-of-line) (point))) |
2205 (dollar (and (eq last-command-char ?$) | 2205 (dollar (and (eq last-command-event ?$) |
2206 (eq this-command 'self-insert-command))) | 2206 (eq this-command 'self-insert-command))) |
2207 (delete (and (memq last-command-char '(?\s ?\n ?\t ?\f)) | 2207 (delete (and (memq last-command-event '(?\s ?\n ?\t ?\f)) |
2208 (memq this-command '(self-insert-command newline)))) | 2208 (memq this-command '(self-insert-command newline)))) |
2209 my do) | 2209 my do) |
2210 (and (save-excursion | 2210 (and (save-excursion |
2211 (condition-case nil | 2211 (condition-case nil |
2212 (progn | 2212 (progn |
2256 (if dollar (progn (search-backward "$") | 2256 (if dollar (progn (search-backward "$") |
2257 (if my | 2257 (if my |
2258 (forward-char 1) | 2258 (forward-char 1) |
2259 (delete-char 1))) | 2259 (delete-char 1))) |
2260 (search-backward ")") | 2260 (search-backward ")") |
2261 (if (eq last-command-char ?\() | 2261 (if (eq last-command-event ?\() |
2262 (progn ; Avoid "if (())" | 2262 (progn ; Avoid "if (())" |
2263 (delete-backward-char 1) | 2263 (delete-backward-char 1) |
2264 (delete-backward-char -1)))) | 2264 (delete-backward-char -1)))) |
2265 (if delete | 2265 (if delete |
2266 (cperl-putback-char cperl-del-back-ch)) | 2266 (cperl-putback-char cperl-del-back-ch)) |
2277 (cperl-ensure-newlines (1- n) pos) | 2277 (cperl-ensure-newlines (1- n) pos) |
2278 (goto-char pos))) | 2278 (goto-char pos))) |
2279 | 2279 |
2280 (defun cperl-electric-pod () | 2280 (defun cperl-electric-pod () |
2281 "Insert a POD chunk appropriate after a =POD directive." | 2281 "Insert a POD chunk appropriate after a =POD directive." |
2282 (let ((delete (and (memq last-command-char '(?\s ?\n ?\t ?\f)) | 2282 (let ((delete (and (memq last-command-event '(?\s ?\n ?\t ?\f)) |
2283 (memq this-command '(self-insert-command newline)))) | 2283 (memq this-command '(self-insert-command newline)))) |
2284 head1 notlast name p really-delete over) | 2284 head1 notlast name p really-delete over) |
2285 (and (save-excursion | 2285 (and (save-excursion |
2286 (forward-word -1) | 2286 (forward-word -1) |
2287 (and | 2287 (and |
2497 (defun cperl-electric-terminator (arg) | 2497 (defun cperl-electric-terminator (arg) |
2498 "Insert character and correct line's indentation." | 2498 "Insert character and correct line's indentation." |
2499 (interactive "P") | 2499 (interactive "P") |
2500 (let ((end (point)) | 2500 (let ((end (point)) |
2501 (auto (and cperl-auto-newline | 2501 (auto (and cperl-auto-newline |
2502 (or (not (eq last-command-char ?:)) | 2502 (or (not (eq last-command-event ?:)) |
2503 cperl-auto-newline-after-colon))) | 2503 cperl-auto-newline-after-colon))) |
2504 insertpos) | 2504 insertpos) |
2505 (if (and ;;(not arg) | 2505 (if (and ;;(not arg) |
2506 (eolp) | 2506 (eolp) |
2507 (not (save-excursion | 2507 (not (save-excursion |
2511 ;; Ignore in comment lines | 2511 ;; Ignore in comment lines |
2512 (= (following-char) ?#) | 2512 (= (following-char) ?#) |
2513 ;; Colon is special only after a label | 2513 ;; Colon is special only after a label |
2514 ;; So quickly rule out most other uses of colon | 2514 ;; So quickly rule out most other uses of colon |
2515 ;; and do no indentation for them. | 2515 ;; and do no indentation for them. |
2516 (and (eq last-command-char ?:) | 2516 (and (eq last-command-event ?:) |
2517 (save-excursion | 2517 (save-excursion |
2518 (forward-word 1) | 2518 (forward-word 1) |
2519 (skip-chars-forward " \t") | 2519 (skip-chars-forward " \t") |
2520 (and (< (point) end) | 2520 (and (< (point) end) |
2521 (progn (goto-char (- end 1)) | 2521 (progn (goto-char (- end 1)) |