随分前の記事に [EmacsのFunction key設定を公開] があるのですが、その後 use-package
から leaf
へ移行したり、内容的にもかなり変遷してきたので V.2版を公開します。
Emacs Function Key の設定
F1: emacs help
F1
は、Emacs標準の helpキーなのでそのまま使います。
which-key.el を導入することで各コマンドのガイドがミニバファーに表示されるので便利です。
(leaf which-key
:ensure t
:config
(which-key-mode 1)
(setq which-key-max-description-length 40)
(setq which-key-use-C-h-commands t))
F2: imenu-list-smart-toggle
counsel-css
と併用することで cssファイル編集時に重宝しています。
(leaf imenu-list
:ensure t
:bind ("<f2>" . imenu-list-smart-toggle)
:config
(setq imenu-list-size 30)
(setq imenu-list-position 'left)
(setq imenu-list-focus-after-activation t))
(leaf counsel-css
:ensure t
:config
(add-hook 'css-mode-hook #'counsel-css-imenu-setup))
F3: filer-current-dir-open
編集中のフィル(または dired)のカレントデレクトリで debianのファルマネージャー nautilus
を開きます。
(defun filer-current-dir-open ()
"Open filer in current dir."
(interactive)
(shell-command (concat "nautilus " default-directory)))
(bind-key "<f3>" 'filer-current-dir-open)
F4: term-current-dir-open
編集中のフィル(または dired)のカレントデレクトリで debianのターミナル gonome-terminal
を開きます。
(defun term-current-dir-open ()
"Open terminal application in current dir."
(interactive)
(let ((dir (directory-file-name default-directory)))
(shell-command (concat "gnome-terminal --working-directory " dir))))
(bind-key "<f4>" 'term-current-dir-open)
eshell
も併用していて、同様に自動的にバッファーファイルのカレントで開くようにしています。
(defun eshell-on-current-buffer ()
"Set the eshell directory to the current buffer."
(interactive)
(let ((path (file-name-directory (or (buffer-file-name) default-directory))))
(with-current-buffer "*eshell*"
(cd path)
(eshell-emit-prompt))))
F5: quickrun
open-junk-fileで書いた perl ruby などのショートコードをバッファーで開いた状態で、即試運転できるすぐれものです。
(leaf quickrun
:ensure t
:bind ("<f5>" . quickrun))
F6: counsel-linux-app
counse.el には Linuxのアプリケーションを呼び出すためのインターフェイスである counsel-linux-app が実装されています。
macOS用のコマンドは Link Text に公開されています。このコマンドのおかげで,Emacs から直接アプリケーションを呼び出せるので便利です。
(bind-key "<f6>" 'counsel-linux-app)
F7: calendar
作業中にカレンダーをチラ見したいときもあります。私の場合、Calfwまでは必要ないので標準機能の calendar
を使っています。F7を押すことで、表示/非表示をトグルします。
japanese-holidays
を installし [土日、今日] を強調させています。
(leaf calendar
:config
(setq calendar-mark-holidays-flag t) ; Show holidays on calendar
(bind-key "<f7>" 'calendar)
(bind-key "<f7>" 'quit-window calendar-mode-map)
(leaf japanese-holidays
:ensure t :require t
:after calendar
:config
(setq calendar-holidays
(append japanese-holidays holiday-local-holidays holiday-other-holidays))
(setq japanese-holiday-weekend '(0 6) ; Show Saturdays and Sundays as holidays
japanese-holiday-weekend-marker ; Saturday is displayed in light blue
'(holiday nil nil nil nil nil japanese-holiday-saturday))
:hook
((calendar-today-visible-hook . japanese-holiday-mark-weekend)
(calendar-today-invisible-hook . japanese-holiday-mark-weekend)
(calendar-today-visible-hook . calendar-mark-today))))
F8: toggle-menu-bar-mode-from-frame
Emacs-24以降で使える機能でメニューバーの表示/非表示をトグルします。デフォルトでは非表示にしていますが、マウスを併用して作業しているときには便利です。
(bind-key "<f8>" 'toggle-menu-bar-mode-from-frame)
F9: display-line-numbers-mode
行番号表示をトグルします。
(leaf display-line-numbers
:bind ("<f9>" . display-line-numbers-mode)
:hook ((prog-mode-hook text-mode-hook) . display-line-numbers-mode))
F10: neotree-toggle
F10は Emacsでは Global Menuのpopupに割り当てられているのだけれど、私の場合は使うことが皆無なので neotree-toggleに割り当てました。
all-the-icons
と組み合わせてもいいのですが doom-themes
を使っている場合は、(doom-themes-neotree-config)
を設定することでよりスッキリした icon表示になります。
(leaf neotree
:ensure t
:bind (("<f10>" . neotree-find)
(:neotree-mode-map
("RET" . neotree-enter-hide)
("a" . neotree-hidden-file-toggle)
("<left>" . neotree-select-up-node)
("<right>" . neotree-change-root)
("<f10>" . neotree-toggle)))
:init
(setq-default neo-keymap-style 'concise)
(setq neo-create-file-auto-open t)
:config
(doom-themes-neotree-config))
F11: Full screen toggle
Windows / macOS / Linux ともデフォルトで F11 に Full screen toggle が割り当てられているので、そのまま使うことにしました。
F12: darkroom-toggle
もっともよく使っている執筆モードです。
darkroom-modeを有効にすると以下のような効果になります。
- 透過を無効
- メニューバー無効
- ツールバー無効
- スクロールバー無効
- fringe無効
- モードライン無効
- テキストが拡大される。初期値は2倍
- 文章を画面中央にもっていく
writeroom-modeとよく似ていますが、defaultでフルスクリーンにならないことと文字サイズが自動的に大きくなるのが特徴です。
桁数の指定はできませんが、ショートカット C-M-+ と C-M-- で表示幅を狭めたり広げたりできます。
darkmode
の基本機能に加えて下記をカスタマイズしています。
- フルスクリーンモード
- C-x 1 (その他のウィンドウを削除)
-
- 行番号表示を消す
- 行間を少し広くする(お好みで…)
(leaf darkroom
:ensure t
:bind ("<f12>" . my:darkroom-mode-in)
:config
(defun my:darkroom-mode-in ()
(interactive)
(toggle-frame-fullscreen)
(delete-other-windows)
(display-line-numbers-mode 0)
(setq line-spacing 0.4)
(darkroom-mode 1)
(bind-key "<f12>" 'my:darkroom-mode-out darkroom-mode-map))
(defun my:darkroom-mode-out ()
(interactive)
(darkroom-mode 0)
(setq line-spacing 0.1)
(display-line-numbers-mode 1)
(toggle-frame-fullscreen)))