Created
December 28, 2014 08:07
-
-
Save xuchunyang/1773c7366152965d03c0 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
;; Narrowing -- use save-restriction | |
(defun my-what-line () | |
"Print the current line number (in the buffer) of point." | |
(interactive) | |
(save-restriction | |
(widen) | |
(save-excursion | |
(beginning-of-line) | |
(message "Line %d" | |
(1+ (count-lines 1 (point))))))) | |
(defun replace-regexp-in-region (start end) | |
(interactive "*r") | |
(save-excursion | |
(save-restriction | |
(let ((regexp (read-string "Regexp: ")) | |
(to-string (read-string "Replacement: "))) | |
(narrow-to-region start end) | |
(goto-char (point-min)) | |
(while (re-search-forward regexp nil t) | |
(replace-match to-string nil nil)))))) | |
(defun display-first-60-chars-of-current-buffer () | |
(interactive) | |
(save-restriction | |
(widen) | |
(message "%s" (buffer-substring-no-properties 1 60)))) | |
(display-first-60-chars-of-current-buffer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment