From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Robert Thorpe Newsgroups: gmane.emacs.help Subject: Re: Regex replace for numbers Date: Fri, 03 Oct 2014 20:22:35 +0100 Message-ID: <87lhoxvtz8.fsf@robertthorpeconsulting.com> References: <87wq8hgqt8.fsf@geodiff-mac3.ulb.ac.be> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1412364197 20994 80.91.229.3 (3 Oct 2014 19:23:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 3 Oct 2014 19:23:17 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, udyantw@gmail.com To: Nicolas Richard Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 03 21:23:10 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xa8RZ-0007TT-6W for geh-help-gnu-emacs@m.gmane.org; Fri, 03 Oct 2014 21:23:09 +0200 Original-Received: from localhost ([::1]:40979 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa8RY-0003UJ-Oe for geh-help-gnu-emacs@m.gmane.org; Fri, 03 Oct 2014 15:23:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa8RB-0003L0-CT for help-gnu-emacs@gnu.org; Fri, 03 Oct 2014 15:22:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xa8R4-000695-JP for help-gnu-emacs@gnu.org; Fri, 03 Oct 2014 15:22:45 -0400 Original-Received: from outbound-smtp01.blacknight.com ([81.17.249.7]:43993) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa8R4-00068r-90 for help-gnu-emacs@gnu.org; Fri, 03 Oct 2014 15:22:38 -0400 Original-Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp01.blacknight.com (Postfix) with ESMTP id 52F9A98FB9 for ; Fri, 3 Oct 2014 19:20:37 +0000 (UTC) Original-Received: (qmail 15156 invoked from network); 3 Oct 2014 19:22:36 -0000 Original-Received: from unknown (HELO RTLaptop) (rt@robertthorpeconsulting.com@[109.79.106.155]) by 81.17.254.9 with ESMTPSA (DHE-RSA-AES128-SHA encrypted, authenticated); 3 Oct 2014 19:22:36 -0000 In-Reply-To: <87wq8hgqt8.fsf@geodiff-mac3.ulb.ac.be> (message from Nicolas Richard on Fri, 03 Oct 2014 16:40:03 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 81.17.249.7 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100253 Archived-At: 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. BR, Robert Thorpe