Created
July 13, 2010 04:43
-
-
Save yaotti/473461 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun insert-str-with-line-context (regexp inserting-str default-char) | |
(let ((ptr (point))) | |
(beginning-of-line) | |
(let ((str (buffer-substring (point) ptr))) | |
(goto-char ptr) | |
(if (string-match regexp str) | |
(insert inserting-str) | |
(insert default-char))))) | |
;; typing "4" inserts "$", not "4" if you wrote "my " or "my (" | |
(define-key cperl-mode-map (kbd "4") | |
(lambda () (interactive) | |
(insert-str-with-line-context "[ \t]*my[ ]+(?$" "$" "4"))) | |
(define-key cperl-mode-map (kbd "8") | |
(lambda () (interactive) | |
(insert-str-with-line-context "[ \t]*my[ ]+$" "(" "8"))) | |
;; typing ":" insert "::" after writing "package ***" | |
(define-key cperl-mode-map (kbd ":") | |
(lambda () (interactive) | |
(insert-str-with-line-context "^package" "::" ":"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment