all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* add slashes
@ 2007-03-29 19:00 Andreas Roehler
  0 siblings, 0 replies; only message in thread
From: Andreas Roehler @ 2007-03-29 19:00 UTC (permalink / raw)
  To: help-gnu-emacs

Just for discussion:

Several functions to escape special chars in region or
line, if no region is active.

Also a function `de-escape'.


__
Andreas Roehler

;;;;;;;

(defun escape-parentheses (&optional beg end)
  " "
  (interactive "*")
  (escape 'parentheses))

(defun escape-star-signs (&optional beg end)
  " "
  (interactive "*")
  (escape 'star))

(defun escape-dollar-signs (&optional beg end)
  " "
  (interactive "*")
  (escape 'dollar))

(defun escape-quotes (&optional beg end)
  " "
  (interactive "*")
  (escape 'quotes))

(defun escape-doublequotes (&optional beg end)
  " "
  (interactive "*")
  (escape 'doublequotes))

(defun escape-backslashes (&optional beg end)
  " "
  (interactive "*")
  (escape 'backslashes))

(defun escape (object &optional beg end)
  " "
  (let ((beg (if beg beg
           (cond ((and mark-active transient-mark-mode)
              (region-beginning))
             (t (line-beginning-position)))))
    (end (if end end
           (cond ((and mark-active transient-mark-mode)
              (1+ (region-end)))
             (t (line-end-position))))))
    (save-excursion
      (funcall (intern-soft (concat "escape-"(symbol-name 
object)"-intern")) beg end))))

(defun escape-quotes-intern (beg end)
  (goto-char beg)
  (while (search-forward "\'" end t 1)
    (replace-match "\\\\\'")
    (setq end (1+ end))))

(defun escape-doublequotes-intern (beg end)
  (goto-char beg)
  (while (search-forward "\"" end t 1)
    (replace-match "\\\\\"")
    (setq end (1+ end))))

(defun escape-backslashes-intern (beg end)
  (goto-char beg)
  (while (re-search-forward "\\\\" end t 1)
    (replace-match "\\\\\\\\")
    (setq end (1+ end))))

(defun escape-dollar-intern (beg end)
  (goto-char beg)
  (while (search-forward "\$" end t 1)
    (replace-match "\\\\\$")
    (setq end (1+ end))))

(defun escape-star-intern (beg end)
  (goto-char beg)
  (while (search-forward "\*" end t 1)
    (replace-match "\\\\\*")
    (setq end (1+ end))))

(defun escape-parentheses-intern (beg end)
  (goto-char beg)
  (while (re-search-forward "\\([()]\\)" end t 1)
    (replace-match "\\\\\\1")
    (setq end (1+ end))))

(defun de-escape ()
  "Removes backslashes in region or line, if no region is active"
  (interactive "*")
  (let ((beg (cond ((and mark-active transient-mark-mode)
            (region-beginning))
           (t (line-beginning-position))))
    (end (cond ((and mark-active transient-mark-mode)
            (region-end))
           (t (line-end-position)))))
    (save-excursion
      (goto-char beg)
      (while (search-forward "\\" end t)
    (replace-match "" end t)
    (setq end (1- end))))))


;; end

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-03-29 19:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-29 19:00 add slashes Andreas Roehler

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.