[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Regex replace for numbers
From: |
Udyant Wig |
Subject: |
Re: Regex replace for numbers |
Date: |
Fri, 03 Oct 2014 17:13:59 +0530 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:
| Instead of solving it with a regexp, I suggest some lisp :
|
| (save-excursion
| (goto-char (point-min))
| (while (re-search-forward "[0-9]" nil t )
| (let ((bounds (bounds-of-thing-at-point 'sexp))
| (number (number-at-point)))
| (when number
| (delete-region (car bounds) (cdr bounds))
| (insert (format "%s" number))))))
|
| (This might not work in modes other than emacs-lisp mode, due to how
| number-at-point works.)
Is there a way to save the major-mode of the buffer before entering the
above code, change to emacs-lisp-mode and then to enable the original
major-mode again?
| <snip tests>
--
Udyant Wig
GitHub: https://github.com/udyant
Poetry: http://www.writing.com/main/profile/biography/frosthrone