[Finda] 一个支持索引 Emacs Buffers 的 Mac Launcher


#1

https://keminglabs.com/finda/

相比 Spotlight、Alfred 和 LaunchBar 等,Finda 非常简单,没什么看似「高级」的功能,比如计算器,默认还支持索引 Emacs Buffers (设置方法),所以我打算先试上一段时间。

(搜索 Emacs 的 *scratch* Buffer)

关于 Emacs 配置

直接用官方的配置,我修改了其中的 finda-switch-to-buffer,为了重用已有的窗口

注:Finda 是个闭源付费(19.99 USD)软件,但可免费试用一段时间。


#2

原理上是用emacsclient获取buffer列表然后模糊匹配?

(defun princ-bufferlist ()
  (->> (buffer-list)
       (-map #'buffer-name)
       (--remove (string-prefix-p " " it))))
130 chino@archlinux ~/.emacs.d (git)-[master] % emacsclient --eval '(princ-bufferlist)'                                                                                                    :(
("*scratch*" "*helpful function: buffer-list*" "*helpful function: buffer-live-p*" "dash-functional.el" "*helpful function: -not*" "*WoMan-Log*" "*WoMan 1perl perlre*" "*WoMan 1perl perl*" "*WoMan 1 split*" "test.perl" "custom.el" "*helpful command: switch-to-buffer*" "*Pp Eval Output*" "*helpful function: string-prefix-p*" "awesome-tab" "magit: awesome-tab" "powerline-separators.el" "powerline-themes.el" "site-lisp" "lib" "etc" "autoloads" "aggressive-indent-mode" "magit-process: awesome-tab" "awesome-tab.el" ".emacs.d" "basic.el" "aggressive-indent.elc" "aggressive-indent.el" "*Messages*" "magit-process: .emacs.d" "magit-diff: .emacs.d" "magit: .emacs.d" "*Flycheck error messages*" "magit-log: awesome-tab" "magit-revision: awesome-tab" "*Help*")
chino@archlinux ~/.emacs.d (git)-[master] % emacsclient -c --eval '(switch-to-buffer "dash-functional.el")'
#<buffer dash-functional.el>

Alfred之类的稍微编下程就能做到?


#3

对,这个工具非常简单

  1. 收集候选项目(窗口、App、文件、浏览器 Tab、浏览器历史、Emacs Buffers);
  2. 用户输入字符串过滤;
  3. 用户按 RET 打开这个选项。

所以不像 Alfred、LaunchBar,这个没啥别的功能,也就没有各种术语(Workflow、Instant Send),也就没学习成本。

可以,我之前也试过


#4

rofi是一个linux下的快速启动栏,它可以从stdin读取补全项,然后输出到stdout。

#!/bin/sh
:; -*- mode: emacs-lisp; coding: utf-8 -*-
:; exec emacsclient -c --eval "(load (expand-file-name \"$0\"))" -- "$@"

(require 'cl-lib)
(require 's)

(defun get-current-buffers ()
  (s-replace-regexp "\n+" "\n"
                    (string-join (thread-last (buffer-list)
                                   (mapcar #'buffer-name)
                                   (cl-remove-if (lambda (it) (string-prefix-p " " it))))
                                 "\n")))

(defun do-switch-buffer ()
  (switch-to-buffer (with-temp-buffer
                      (erase-buffer)
                      (shell-command (format "echo '%s' | rofi -matching fuzzy  -dmenu" (get-current-buffers)) (current-buffer))
                      (s-trim (buffer-string)))))


(do-switch-buffer)

为什么没有截图演示?因为rofi进入之后就拦截了键盘事件。我flameshot都用不了了


有趣的玩法。妈妈再也不用担心helm和ivy的补全太丑了

(defun Mx-with-rofi ()
  (interactive)
  (ignore-errors
    (command-execute (intern-soft
                      (with-temp-buffer
                        (erase-buffer)
                        (shell-command (format "echo '%s' | rofi -matching fuzzy -dmenu"
                                               (s-join "\n" (counsel--M-x-externs)))
                                       (current-buffer))
                        (s-trim (buffer-string)))) 'record)))