GNU Emacs 32.0.50 (9008bf64c3) のマニュアルを PLaMo 翻訳で機械翻訳したものです。誤訳を含むことがあります。原文: https://www.gnu.org/software/emacs/manual/html_node/eintr/Simple-Extension.html ・ emacs-doc.conao3.com

16.11 シンプルな拡張: line-to-top-of-window

ポイントがある行をウィンドウの最上部に移動させる、Emacs用のシンプルな拡張機能です。テキストを読みやすくするために、いつも使っています。

以下のコードを別ファイルに記述して.emacsファイルから読み込むか、あるいは.emacsファイル内に記述することもできます。

定義は以下の通りです:

;;; Line to top of window;
;;; replace three keystroke sequence  C-u 0 C-l
(defun line-to-top-of-window ()
  "Move the line that point is on to top of window."
  (interactive)
  (recenter 0))

次はキーバインドです。

ファンクションキーのほか、マウスボタンイベントや非ASCII文字は、引用符なしで角括弧内に記述します。

次のように line-to-top-of-window を F6 ファンクションキーにバインドします。

(keymap-global-set "<f6>" 'line-to-top-of-window)

詳細については、The GNU Emacs ManualのInitファイルでのキーの再割り当てを参照してください。

GNU Emacs のバージョン 27 と 28 のように 2 つのバージョンを動作させ、1 つの .emacs ファイルを使用する場合、以下の条件式で評価するコードを選択できます。

(cond
 ((= 27 emacs-major-version)
  ;; evaluate version 27 code
  ( ... ))
 ((= 28 emacs-major-version)
  ;; evaluate version 28 code
  ( ... )))

例えば、最近のバージョンではデフォルトでカーソルが点滅します。私はこのような点滅やその他の機能が嫌いなので、.emacs ファイルに以下を記述しました21:

(when (>= emacs-major-version 21)
  (blink-cursor-mode 0)
  ;; Insert newline when you press 'C-n' (next-line)
  ;; at the end of the buffer
  (setq next-line-add-newlines t)
  ;; Turn on image viewing
  (auto-image-file-mode t)
  ;; Turn on menu bar (this bar has text)
  ;; (Use numeric argument to turn on)
  (menu-bar-mode 1)
  ;; Turn off tool bar (this bar has icons)
  ;; (Use numeric argument to turn on)
  (tool-bar-mode nil)
  ;; Turn off tooltip mode for tool bar
  ;; (This mode causes icon explanations to pop up)
  ;; (Use numeric argument to turn on)
  (tooltip-mode nil)
  ;; If tooltips turned on, make tips appear promptly
  (setq tooltip-delay 0.1)  ; default is 0.7 second
   )

脚注

(21)

.emacsファイルやサイトファイルを読み込まないEmacsインスタンスを起動する際は、点滅もオフにしています:

emacs -q --no-site-file -eval '(blink-cursor-mode nil)'

Or nowadays, using an even more sophisticated set of options,

emacs -Q -D