在整个缓冲区中查找并替换 emacs23

在整个缓冲区中查找并替换 emacs23

我已经使用 emacs 多年了,但绝不是专家。当我获得新版本的 Ubuntu 时,我获得了最新版本的 emacs (24),但我讨厌它,所以又回到了 emacs23。它和我习惯的一样,只是查找和替换功能不能按照我想要的方式工作。我习惯于在文档的任何位置,按 Mx %,然后键入我的搜索和替换字符串,按回车键,然后在文档的其余部分进行替换。它现在不再这样做了。如果我不选择区域,它甚至不会尝试查找任何实例。如果我选​​择了一个区域,并且它在我的窗口中完全可见,它将进行搜索和替换。如果我突出显示了一个比我的窗口大的区域,它只会在该区域的可见部分进行搜索和替换。这真是令人抓狂。

我认为这与“transient-mark-mode”有关,该模式在 emacs23 中默认启用,人们描述了我看到的行为。但是当我使用 Mx temporary-mark-mode 将其关闭时,或者在我的 .emacs 文件中,没有任何变化。我做错了什么?

答案1

我无法重现您的问题,但可能是您启用了 cua-mode,并且它阻止关闭 temporary-mark-mode。尝试切换,M-x cua-mode直到您得到已禁用,然后切换,M-x transient-mark-mode直到你得到它已禁用.然后检查这是否能解决您的问题。

来源

顺便说一句,我觉得您喜欢 Emacs23(因为您已经使用它很多年了)却讨厌 Emacs24,这听起来很奇怪。您在尝试 Emacs24 时出了什么问题?

编辑

下面是query-replace-regexp-to-the-end-of-buffer-or-in-a-regiondefun 可以完成您想要的操作:

(defun query-replace-regexp-to-the-end-of-buffer-or-in-a-region (point)
  "If there's a region - query replaces regexp in region, 
   otherwise replaces from current point to the end of buffer."
  (interactive "d")
  (let (start end)
    (if (use-region-p)
        (progn (setq start (region-beginning)) ;; then
               (setq end (region-end)))
      (progn (setq start point) ;; else
             (setq end (point-max))))
    (set-mark start)
    (goto-char end)
    (apply #'query-replace-regexp 
           (let ((common (query-replace-read-args (concat "Query replace regexp") t))) 
             (list (nth 0 common) (nth 1 common) (nth 2 common) (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end)))))))

只需将其绑定到某个键,甚至可以是M-%

相关内容