[Top][All Lists]

[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 <> writes:

> Udyant Wig <> 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.

Robert Thorpe

reply via email to

[Prev in Thread] Current Thread [Next in Thread]