search - 在 Emacs 中使用 swiper 模拟 helm-swoop
问题描述
长期 Emacshelm
用户在这里。我最近一直ivy
在尝试,我正在尝试在 Emacs 内部helm-swoop
进行模拟。swiper
具体来说,如果我在框架内打开了许多窗口,我想要以下行为:
- 暂时关闭所有窗口。
- 水平分割屏幕并
swiper
在另一个窗口中显示结果。如果当前缓冲区的窗口在左侧,则在右侧显示结果,反之亦然。 - 完成后,恢复所有窗口。
我目前有这个工作,但是当当前缓冲区的窗口在左侧时,点击RET
最终搜索结果不会导航到原始缓冲区中的那个位置。但是,如果当前缓冲区的窗口位于右侧,则一切正常。
这是我到目前为止的ELisp代码:
(defun ivy-display-function-other-window (text)
"Show ivy results in other window."
(let ((buffer (get-buffer-create "*ivy-candidate-window*"))
(str (with-current-buffer (get-buffer-create " *Minibuf-1*")
(let ((point (point))
(string (concat (buffer-string) " " text)))
(add-face-text-property
(- point 1) point 'ivy-cursor t string)
string))))
(with-current-buffer buffer
(let ((inhibit-read-only t))
(erase-buffer)
(insert str)))
(with-ivy-window
(display-buffer
buffer
`((display-buffer-reuse-window
(lambda (buffer alist)
(other-window 1)
(switch-to-buffer buffer))))))))
(defun my-swiper (&optional initial-input)
"Opens swiper in a vertical buffer."
(interactive)
(let ((position (point)))
(save-window-excursion
(let* ((buffer (current-buffer))
(window (get-buffer-window))
(should-swap
(and
(not (window-at-side-p window 'left))
(window-at-side-p window 'right)))
(ivy-height (1- (window-height window))))
(delete-other-windows)
(split-window-horizontally)
(when should-swap
(other-window 1)
(switch-to-buffer buffer))
(setq position (swiper initial-input))))
(goto-char position)))
...
(use-package counsel
:ensure t
:demand t
:bind
(("M-i" . my-swiper))
...
(setq ivy-display-functions-alist
'((swiper . ivy-display-function-other-window)))
这里是GitHub 上来自wikiivy-display-function-other-window
的稍微编辑的版本。谢谢!ivy-display-function-window
ivy
解决方案
推荐阅读
- sql - 在 Laravel 中同时使用 group by 和 count 以及 where 查询
- reactjs - 在同一存储库中的 github 页面前端和后端部署 React 应用程序
- r - 找出异常值并将它们设置为 NA
- javascript - Bot Framework V4 - TypeError:无法在已撤销的代理上执行“获取”
- c++ - 如何将 C++ 权重向量添加到 C++ 中的 caffe 模型
- python - ModuleNotFoundError:没有名为“tensorflow”的模块,即使安装了 tensorflow
- ios - 在过滤器选择上存储数据
- asp.net-mvc - 在 html 和 javascripts 中处理包含 Razor 语法的字符串
- scala - SpringDataForCassandra:当 Int 列在 DB 中设置为空时,实体中的 NullPointerEx
- ios - 来自变量的 ViewController Storyboard ID