all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Decebal <cldwesterhof@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Function to replace space on the beginning of a line with nbsp
Date: Sat, 10 Oct 2009 02:01:51 -0700 (PDT)	[thread overview]
Message-ID: <4df48b40-c086-498f-9380-d6ecfac9e2ea@m38g2000yqd.googlegroups.com> (raw)

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 "^ +" " ") ;the character in
the replace string is chr$(160)
  )

(defun start-with-spaces(begin end)
  (interactive "r")
  (replace-regexp-with-string begin end "^ +" " ")
  )

Hope that it is usefull to someone.


                 reply	other threads:[~2009-10-10  9:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4df48b40-c086-498f-9380-d6ecfac9e2ea@m38g2000yqd.googlegroups.com \
    --to=cldwesterhof@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.