Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs 替换非活动缓冲区中的字_Emacs - Fatal编程技术网

Emacs 替换非活动缓冲区中的字

Emacs 替换非活动缓冲区中的字,emacs,Emacs,如果我打开了两个缓冲区(并排),并且我从一个窗口移动到另一个窗口,我可以用活动窗口中光标下的一个替换第一个(现在不活动)窗口中以前选择的字吗 \u是光标 _______________ | foo | _bar | | | | | | | | | | |_______|_______| 是否有一个内部命令可以让我快速地将foo替换为bar?没有内部命令,但这是Emacs: (def

如果我打开了两个缓冲区(并排),并且我从一个窗口移动到另一个窗口,我可以用活动窗口中光标下的一个替换第一个(现在不活动)窗口中以前选择的字吗

\u
是光标

  _______________
 | foo   | _bar  |          
 |       |       |
 |       |       |
 |       |       |
 |_______|_______| 

是否有一个内部命令可以让我快速地将
foo
替换为
bar

没有内部命令,但这是Emacs:

(defun replace-word-other-window ()
  (interactive)
  (let ((sym (thing-at-point 'symbol))
        bnd)
    (other-window 1)
    (if (setq bnd (bounds-of-thing-at-point 'symbol))
        (progn
          (delete-region (car bnd) (cdr bnd))
          (insert sym))
      (message "no symbol at point in other window"))
    (other-window -1)))
更新:高级版本
令人惊叹的!谢谢这很有效。你能帮我扩展一下吗。在单词被替换后,我需要关闭该窗口(
退出窗口
可能会这样),跳回第一个窗口并将其解锁(C-x 0)。您需要
(删除窗口)
。把它放在
信息之后就行了。太酷了!现在,你必须帮我修复一个选择:)现在它对单个单词有效,但我如何为已选择的内容制作它<代码>点上的东西
似乎忽略了选择
(defun region-or-symbol-bounds ()
  (if (region-active-p)
      (cons (region-beginning)
            (region-end))
    (bounds-of-thing-at-point 'symbol)))

(defun replace-word-other-window ()
  (interactive)
  (let* ((bnd-1 (region-or-symbol-bounds))
         (str-1 (buffer-substring-no-properties
                 (car bnd-1)
                 (cdr bnd-1)))
         (bnd-2 (progn
                  (other-window 1)
                  (region-or-symbol-bounds))))
    (if bnd-2
        (progn
          (delete-region (car bnd-2) (cdr bnd-2))
          (insert str-1))
      (message "no region or symbol at point in other window"))
    (other-window -1)))