[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex replace for numbers

From: Nicolas Richard
Subject: Re: Regex replace for numbers
Date: Fri, 03 Oct 2014 16:40:03 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.93 (gnu/linux)

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
    (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)))))))

Nicolas Richard

reply via email to

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