* Function to replace space on the beginning of a line with nbsp
@ 2009-10-10 9:01 Decebal
0 siblings, 0 replies; only message in thread
From: Decebal @ 2009-10-10 9:01 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-10-10 9:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-10 9:01 Function to replace space on the beginning of a line with nbsp Decebal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).