[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Function to replace space on the beginning of a line with nbsp
From: |
Decebal |
Subject: |
Function to replace space on the beginning of a line with nbsp |
Date: |
Sat, 10 Oct 2009 02:01:51 -0700 (PDT) |
User-agent: |
G2/1.0 |
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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Function to replace space on the beginning of a line with nbsp,
Decebal <=