[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Regex replace for numbers
From: |
Robert Thorpe |
Subject: |
Re: Regex replace for numbers |
Date: |
Fri, 03 Oct 2014 20:22:35 +0100 |
Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:
> Udyant Wig <udyantw@gmail.com> writes:
>> 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?
>
> You don't really need to do that. Simply using the syntax table should
> be sufficient in this case :
>
> (with-syntax-table emacs-lisp-mode-syntax-table
> (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)))))))
Thanks everyone. I'll try the elisp solution and the regexps solution.
BR,
Robert Thorpe