在Emacs中的点处替换字符

时间:2014-04-04 01:47:32

标签: emacs elisp

在Emacs Lisp中是否有任何替换字符的函数?

目前我能做的是:

(goto-char pt)
(delete-char 1)
(insert c)

2 个答案:

答案 0 :(得分:1)

我不认为有这样做的功能,但当然你可以将上述内容包装起来。

答案 1 :(得分:0)

有一些常见的替代品,例如切换外壳,切换"("到")",提高/降低数字。可能会完成以下任务:

(defun reverse-chars (&optional arg)
  "Reverse reciproke chars as \"[\" to \"]\", upcase or downcase,
Switch `\"' with `''

If over a number, add ARG to it.
With negative arg, substract from number.
Et EOB, look backward for next number. "
  (interactive "*p")
  (let (i done)
    (if (looking-at "[0-9]")
        (ar-add-to-number arg)
      (let* ((cf (char-after))
             (cn (when (char-or-string-p cf)(downcase cf))))
        (cond ((or (eobp)(eq cf 32)(eq cf ?\ ))
               (when (< 0 (abs (skip-chars-backward "^0-9" (line-beginning-position))))
                 (forward-char -1)
                 (ar-add-to-number arg)
                 (setq done t)))
              ((eq cf 34) ;; ?\"
               (setq cn "'"))
              ((eq cf 39) ;; ?\'
               (setq cn "\""))
              ((eq cf 43) ;; ?\+
               (setq cn "-"))
              ((eq cf 62) ;; ?\>
               (setq cn "<"))
              ((eq cf 60) ;; ?\<
               (setq cn ">"))
              ((eq cf 187) ;; ?\»
               (setq cn "«"))
              ((eq cf 171) ;; ?\«
               (setq cn "»"))
              ((eq cf 41) ;; ?\)
               (setq cn "("))
              ((eq cf 40) ;; ?\(
               (setq cn ")"))
              ((eq cf 123)
               (setq cn "}")) 
              ((eq cf 125) 
               (setq cn "{"))
              ((eq cf 93) ;; ?\]
               (setq cn "["))
              ((eq cf 91) ;; ?\[
               (setq cn "]"))
              ((eq cf 45) ;; ?\-
               (setq cn "_"))
              ((eq cf 95) ;; ?\_
               (setq cn "-"))
              ((eq cf 92) ;; ?\\
               (setq cn "/"))
              ((eq cf 47) ;; ?\/
               (setq cn "\\"))
              (t (when (eq cf cn)
                   (setq cn (upcase cf)))))
        (unless done
          (delete-char 1)
          (insert cn))))))