From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Decebal Newsgroups: gmane.emacs.help Subject: Function to replace space on the beginning of a line with nbsp Date: Sat, 10 Oct 2009 02:01:51 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4df48b40-c086-498f-9380-d6ecfac9e2ea@m38g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1255167799 16747 80.91.229.12 (10 Oct 2009 09:43:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 Oct 2009 09:43:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Oct 10 11:43:11 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MwYTm-0007b4-Nl for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Oct 2009 11:43:11 +0200 Original-Received: from localhost ([127.0.0.1]:45783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MwYTm-0002ku-AH for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Oct 2009 05:43:10 -0400 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!m38g2000yqd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 36 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: posting.google.com 1255165311 13512 127.0.0.1 (10 Oct 2009 09:01:51 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 10 Oct 2009 09:01:51 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m38g2000yqd.googlegroups.com; posting-host=84.53.123.169; posting-account=K-cdeAoAAAD_0d505kUtHXJaT5LFIu-3 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:173717 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68808 Archived-At: Because sometimes I want to put indented things on LinkedIn and there is no way to do this in a normal way, I made a function to change te starting spaces of a region to nbsp. (Those are displayed correctly.) Offcourse I made a function for the reverse and a general function to change a regulair expression with a string (maybe severall times) for the same length. The functions: (defun replace-regexp-with-string(begin end reg-exp substitute-str) (interactive "r\nsregulair expression: \nssubstitutie string: ") (let ((max-length)) (save-excursion (save-restriction (narrow-to-region begin end) (goto-char (point-min)) (while (re-search-forward reg-exp nil t) (setq match-length (- (point) (match-beginning 0))) (while (> match-length (length substitute-str)) (setq substitute-str (concat substitute-str substitute- str))) (replace-match (substring substitute-str 0 match- length)))))) (deactivate-mark)) (defun start-with-nbsp(begin end) (interactive "r") (replace-regexp-with-string begin end "^ +" "=A0") ;the character in the replace string is chr$(160) ) (defun start-with-spaces(begin end) (interactive "r") (replace-regexp-with-string begin end "^=A0+" " ") ) Hope that it is usefull to someone.