Last active
February 16, 2024 04:04
-
-
Save tam17aki/d8cfc161d3dd064eae8de8d58f7f4007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 起動時間をメッセージバッファに表示 | |
(add-hook 'after-init-hook | |
(lambda () | |
(message "init time: %.3f sec" | |
(float-time (time-subtract after-init-time before-init-time))))) | |
;; ロードパスの設定 | |
(add-to-list 'load-path "~/.emacs.d/lisp/") | |
;; C-zを無効化 | |
(global-unset-key "\C-z") | |
;; | |
(defalias 'lp 'list-packages) | |
;; theme | |
(load-theme 'solarized-light t) | |
;; 言語設定 & mozc | |
(set-language-environment 'utf-8) | |
(setq default-input-method "japanese-mozc") | |
(prefer-coding-system 'utf-8) | |
(with-eval-after-load 'mozc | |
(require 'mozc-popup) | |
(setq mozc-candidate-style 'popup) | |
(require 'mozc-temp) | |
(setq mozc-temp-remove-pre-space nil) ;; 変換時のpreスペース削除を抑制する | |
(global-set-key (kbd "M-j") #'mozc-temp-convert)) | |
;; w3m | |
(add-hook 'w3m-mode-hook | |
#'(lambda () | |
(display-line-numbers-mode -1))) | |
(with-eval-after-load "w3m" | |
(define-key w3m-mode-map (kbd "C-;") 'ace-link)) | |
;; eww | |
(setq eww-search-prefix "https://www.google.co.jp/search?q=") | |
(setq shr-use-fonts nil) | |
(add-hook 'eww-mode-hook | |
#'(lambda () | |
(defun eww-mode-hook--rename-buffer () | |
"Rename eww browser's buffer so sites open in new page." | |
(rename-buffer "eww" t)) | |
(add-hook 'eww-mode-hook 'eww-mode-hook--rename-buffer) | |
(defun eww-disable-images () | |
"eww で画像表示させない" | |
(interactive) | |
(setq-local shr-put-image-function 'shr-put-image-alt) | |
(eww-reload)) | |
(defun eww-enable-images () | |
"eww で画像表示させる" | |
(interactive) | |
(setq-local shr-put-image-function 'shr-put-image) | |
(eww-reload)) | |
(defun shr-put-image-alt (spec alt &optional flags) | |
(insert alt)) | |
;; はじめから非表示 | |
(defun eww-mode-hook--disable-image () | |
(setq-local shr-put-image-function 'shr-put-image-alt)) | |
(eww-mode-hook--disable-image) | |
(display-line-numbers-mode -1))) | |
(with-eval-after-load "eww" | |
(ace-link-setup-default) | |
(define-key eww-mode-map (kbd "o") #'ace-link-eww) | |
(define-key eww-mode-map "r" 'eww-reload) | |
(define-key eww-mode-map "c 0" 'eww-copy-page-url) | |
(define-key eww-mode-map "p" 'scroll-down) | |
(define-key eww-mode-map "n" 'scroll-up) | |
(defvar eww-disable-colorize t) | |
(defun shr-colorize-region--disable (orig start end fg &optional bg &rest _) | |
(unless eww-disable-colorize | |
(funcall orig start end fg))) | |
(advice-add 'shr-colorize-region :around #'shr-colorize-region--disable) | |
(advice-add 'eww-colorize-region :around #'shr-colorize-region--disable) | |
(defun eww-disable-color () | |
"eww で文字色を反映させない" | |
(interactive) | |
(setq-local eww-disable-colorize t) | |
(eww-reload)) | |
(defun eww-enable-color () | |
"eww で文字色を反映させる" | |
(interactive) | |
(setq-local eww-disable-colorize nil) | |
(eww-reload)) | |
) | |
;; tab-bar | |
(with-eval-after-load 'tab-bar | |
(setq tab-bar-tab-hints t) ;; タブに番号表示 | |
(setq tab-bar-new-button-show nil) ;; 新規タブボタンは非表示 | |
(setq tab-bar-close-button-show nil) ;; タブ削除ボタンは非表示 | |
(setq tab-bar-new-tab-to 'rightmost) ;; 新規タブは一番右 | |
(setq tab-bar-format '(tab-bar-format-tabs tab-bar-separator)) ;; ヒストリのボタンは不要 | |
(tab-bar-history-mode 1) ;; 各タブについて,ウィンドウ構成のヒストリを記憶する | |
(desktop-save-mode 1) ;; tabの構成を含めて復元できる(実質的な永続化の実現) | |
;; タブ名に保持しているウィンドウの数を付記する | |
(setq tab-bar-tab-name-function 'tab-bar-tab-name-current-with-count) | |
;; タブ番号に基づいてワンストロークで移動する | |
(defvar tab-bar-switch-prefix "C-M-%d") ;; C-M-1はタブ番号1への移動, C-M-2はタブ番号2への移動 | |
(defvar tab-bar-top-tab "1") | |
(defvar tab-bar-bottom-tab "9") | |
(defun tab-bar-set-keybind () | |
(mapc (lambda (i) | |
(global-set-key (kbd (format tab-bar-switch-prefix i)) | |
`(lambda () | |
(interactive) | |
(tab-bar-select-tab ,(int-to-string i))))) | |
(number-sequence (string-to-number tab-bar-top-tab) | |
(string-to-number tab-bar-bottom-tab)))) | |
(tab-bar-set-keybind)) | |
;; Emacs29 | |
(global-set-key (kbd "C-x j") #'duplicate-dwim) | |
(defun kill-whole-line2 () | |
(interactive) | |
(kill-whole-line) | |
(back-to-indentation)) | |
(global-set-key (kbd "C-S-k") 'kill-whole-line2) | |
;; 起動時の画面をオフ | |
(setq inhibit-startup-message t) | |
;; 警告音を完全に消す | |
(setq ring-bell-function 'ignore) | |
;;リージョンに色をつける | |
(setq transient-mark-mode t) | |
;; 折り返し表示 | |
(setq truncate-lines nil) | |
;; 起動時のフレームサイズを設定する | |
(setq initial-frame-alist | |
(append (list | |
'(width . 190) | |
'(height . 50) | |
'(top . 0) | |
) | |
initial-frame-alist)) | |
(setq default-frame-alist initial-frame-alist) | |
;; ツールバーを非表示 | |
(tool-bar-mode -1) | |
;; カーソルを点滅させない | |
(blink-cursor-mode -1) | |
;; 余計なファイルを生成させない | |
(setq make-backup-files nil) | |
(setq auto-save-default nil) | |
(setq auto-save-list-file-prefix nil) | |
;; C-x C-c で閉じる時に、ワンクッション置く | |
(setq confirm-kill-emacs 'y-or-n-p) | |
;; バックアップファイルを作らない | |
(setq backup-inhibited t) | |
;; t: 行全体を削除 | |
(setq kill-whole-line t) | |
;; set tab width as 4 | |
(setq-default tab-width 4) | |
;; tab width = 4 | |
(setq tab-stop-list (number-sequence 4 60 4)) | |
;; インデントはスペースで | |
(setq indent-tabs-mode nil) | |
;; auto-revert (emacs以外からファイル編集されたときに再読込) | |
(global-auto-revert-mode t) | |
;; インデントの改善 | |
(defun all-indent () | |
(interactive) | |
(save-excursion | |
(indent-region (point-min) (point-max)))) | |
(defun electric-indent () | |
"Indent specified region. | |
When resion is active, indent region. | |
Otherwise indent whole buffer." | |
(interactive) | |
(if (use-region-p) | |
(indent-region (region-beginning) (region-end)) | |
(all-indent))) | |
;; bookmarkの拡張 bm.el | |
(global-set-key (kbd "C-2") 'bm-toggle) | |
(global-set-key (kbd "C-7") 'bm-previous) | |
(global-set-key (kbd "C-8") 'bm-next) | |
;; ウィンドウのタイトルに | |
;; バージョン名,ファイルのフルパス,日付・時刻を表示する | |
;; https://qiita.com/fujimotok/items/28b03a05224cedd0cc5a | |
(setq display-time-interval 30) | |
(setq display-time-string-forms | |
'((format "[ %s/%s/%s(%s) %s:%s ]" | |
year month day dayname 24-hours minutes))) | |
;; year (A.D.) | |
;; month (1 -> 12) | |
;; day (1 -> 31) | |
;; dayname -- Sun, Mon, Tue, Wed, Thu, Fri, Sat | |
;; 24-hours (0 -> 23) | |
;; minutes (0 -> 59) | |
;; seconds (0 -> 59) | |
;; display date on the left side of time | |
(setq display-time-24hr-format t) | |
(setq display-time-day-and-date t) | |
(defvar title-time-mode t | |
"This is set to t iff we are displaying the current time in the title bar.") | |
(defun title-time-set () | |
"Set `frame-title-format' to the local system name followed by date, | |
time, and load information (as per `display-time-string-forms') and perhaps | |
followed by an appointment notification." | |
(setq frame-title-format | |
(concat (format "Emacs%s@%s : %%f" emacs-version (system-name)) | |
" - " display-time-string))) | |
(defun title-time-update () | |
"Update the time display in the title-bar. | |
Skips inferior frames, that is, those without a minibuffer (eg. speedbar). " | |
(interactive) | |
;; remove time display from the mode line | |
(delq 'display-time-string global-mode-string) | |
(delq 'appt-mode-string global-mode-string) | |
(let ((start-frame (selected-frame))) | |
(save-excursion | |
(save-window-excursion | |
(let ((my-frame-list (frame-list)) | |
(my-frame nil)) | |
(while (setq my-frame (car my-frame-list)) | |
(when (frame-parameter my-frame 'minibuffer) | |
(frame-parameter nil 'frame-title-format) | |
(select-frame my-frame) | |
(title-time-set)) | |
(setq my-frame-list (cdr my-frame-list)))))) | |
(select-frame start-frame))) | |
(add-hook 'display-time-hook #'title-time-update) | |
;; 時間表示 | |
(display-time-mode 1) | |
(defun my/exchange-point-and-mark () | |
"`exchange-point-and-mark' without mark activatation." | |
(interactive) | |
(exchange-point-and-mark) | |
(deactivate-mark)) | |
(global-set-key (kbd "C-x C-x") #'exchange-point-and-mark) | |
(global-set-key (kbd "C-x C-.") #'my/exchange-point-and-mark) | |
;; 複数箇所の同時編集 iedit | |
;; (global-set-key (kbd "C-;") #'iedit-mode) | |
;; ウィンドウ構成を記憶し,undo/redoできる | |
;; winner-undo, winner-redo | |
(winner-mode) | |
(global-unset-key (kbd "C-t")) | |
(require 'smartrep nil t) | |
(smartrep-define-key global-map "C-t" | |
'( | |
("C-n" . 'mc/mark-next-like-this) | |
("C-p" . 'mc/mark-previous-like-this) | |
)) | |
;; ウィンドウ操作系 | |
(smartrep-define-key global-map "C-c" | |
'(("C-{" . 'shrink-window-horizontally) | |
("C-}" . 'enlarge-window-horizontally) | |
("+" . 'balance-windows) | |
(":" . 'enlarge-window) | |
("^" . 'enlarge-window) | |
("%" . 'shrink-window) | |
("\"" . 'shrink-window) | |
)) | |
;; 日本語も補完対象 | |
(require 'dabbrev-ja) | |
;; 気の利いた補完 | |
;; 日本語も補完対象 | |
;; (global-set-key (kbd "M-/") #'hippie-expand) | |
;; (global-set-key (kbd "M-/") #'dabbrev-expand) | |
(add-to-list 'completion-at-point-functions #'cape-dabbrev) | |
(global-set-key (kbd "C-M-/") #'cape-dabbrev) | |
(setq dabbrev-case-fold-search nil) ;; nil 検索時に大文字と小文字を区別する | |
(setq dabbrev-case-replace nil) ;; nil 展開時に大文字と小文字を区別する | |
(add-to-list 'completion-at-point-functions #'dabbrev-capf) | |
(with-eval-after-load 'dabbrev | |
(add-to-list 'dabbrev-ignored-buffer-regexps "\\` ") | |
(add-to-list 'dabbrev-ignored-buffer-modes 'doc-view-mode) | |
(add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode)) | |
(setq hippie-expand-try-functions-list | |
'( | |
try-expand-dabbrev | |
try-expand-dabbrev-all-buffers | |
;; try-expand-dabbrev-from-kill | |
try-complete-lisp-symbol-partially | |
try-complete-lisp-symbol | |
try-complete-file-name-partially | |
try-complete-file-name | |
try-expand-all-abbrevs | |
;; try-expand-list | |
;; try-expand-line | |
)) | |
;; mode-lineにウィンドウ番号を表示,ALT+数字キーで移動 | |
(window-numbering-mode +1) | |
;; リージョンを選択中に入力したテキストで上書き | |
(delete-selection-mode 1) | |
;;; ナローイングを有効化 | |
(put 'narrow-to-region 'disabled nil) | |
(put 'narrow-to-page 'disabled nil) | |
(put 'narrow-to-defun 'disabled nil) | |
(global-set-key (kbd "S-<right>") #'split-window-left) | |
(global-set-key (kbd "S-<left>") #'delete-other-windows) | |
(global-set-key (kbd "S-<up>") #'split-window-above) | |
(global-set-key (kbd "S-<down>") #'delete-window) | |
(global-set-key (kbd "<left>") #'windmove-left) | |
(global-set-key (kbd "<down>") #'windmove-down) | |
(global-set-key (kbd "<up>") #'windmove-up) | |
(global-set-key (kbd "<right>") #'windmove-right) | |
(defun split-window-above (&optional size) | |
"画面分割したとき下のウィンドウがアクティヴになる." | |
(interactive) | |
(split-window nil size 'above)) | |
(global-set-key "\C-x2" #'split-window-above) | |
(defun split-window-left (&optional size) | |
"画面分割したとき右のウィンドウがアクティヴになる." | |
(interactive) | |
(split-window nil size 'left)) | |
(global-set-key "\C-x3" #'split-window-left) | |
;; 現在行のハイライト | |
;; カラムのハイライトはvline-mode | |
(global-hl-line-mode 1) | |
;; 行番号の表示 | |
(setq-default indicate-empty-lines t) | |
(setq-default indicate-buffer-boundaries 'left) | |
(column-number-mode) | |
;; 長いファイルを開く場合でも行番号を常に表示 | |
(setq line-number-display-limit-width 100000) | |
(add-hook 'prog-mode-hook #'display-line-numbers-mode) | |
;; モードラインに現在行数と総行数を同時に表示 | |
(defvar my-mode-line-format nil) | |
(setq my-mode-line-format " (%%l/%d,%%c)") | |
(if size-indication-mode | |
(setq my-mode-line-format (concat my-mode-line-format " of %%I"))) | |
(setq mode-line-position | |
'(:eval (format my-mode-line-format | |
(count-lines (point-min) (point-max))))) | |
;; 今バッファに表示している範囲を(矢印を用いて)フリンジに表示する | |
(setq-default indicate-buffer-boundaries 'left) | |
;; C-u C-SPC C-SPC C-SPC... のように C-SPC を連続で入力するだけで, | |
;; 連続でマークを辿れるように | |
(setq set-mark-command-repeat-pop t) | |
(keyboard-translate ?\C-h ?\C-?) | |
(global-set-key "\C-h" nil) ; enable to use backspace key in isearch mode | |
(autoload 'goto-last-change "goto-chg" nil t) | |
(global-set-key (kbd "<f8>") 'goto-last-change) | |
;; OS側の別アプリ経由でクリップボードにコピーした内容をEmacsに貼り付ける | |
(global-set-key (kbd "C-M-y") 'clipboard-yank) | |
;; バッファリストの表示 | |
;; c キーでconfigを次々に変える | |
(global-set-key (kbd "C-x C-b") 'bs-show) | |
;; (global-set-key (kbd "M-]") 'bs-cycle-next) | |
;; (global-set-key (kbd "M-[") 'bs-cycle-previous) | |
(setq bs-default-configuration "files-and-dirs") | |
(with-eval-after-load "bs" | |
(defun my-visits-non-file-or-dir (buffer) | |
(and (not (buffer-file-name buffer)) | |
(not (eq (buffer-local-value 'major-mode buffer) 'dired-mode)))) | |
(add-to-list 'bs-configurations | |
'("files-and-dirs" nil nil nil my-visits-non-file-or-dir | |
bs-sort-buffer-interns-are-last))) | |
;; バッファ名の一意化 | |
(setq uniquify-buffer-name-style 'post-forward-angle-brackets) | |
(setq uniquify-ignore-buffers-re "*[^*]+*") | |
(require 'thingopt) | |
(define-thing-commands) | |
(global-set-key (kbd "C-,") #'mark-word*) | |
(global-set-key (kbd "C-.") #'mark-symbol) | |
(global-set-key (kbd "C-M-,") #'mark-string) | |
(global-set-key (kbd "C-M-.") #'mark-up-list) | |
;; スクロールは1行ごとに | |
(setq mouse-wheel-scroll-amount '(1 ((shift) . 5))) | |
;; スクロールの加速をやめる | |
(setq mouse-wheel-progressive-speed nil) | |
;; dired | |
;; C コピー(cp) | |
;; R リネーム/移動 (mv) | |
;; D 削除(rm) | |
;; M 権限操作(chmod) | |
;; G グループ変更(chgrp) | |
;; O 所有権変更(chown) | |
;; Z 圧縮/展開(compress/uncompress/gunzip/bunzip/unzip) | |
;; B (*.elファイルの)バイトコンパイル | |
;; ! 任意のコマンドの実行。デフォルトで空気読んだコマンドになってる。 | |
;; dired-filter | |
;; /d ディレクトリのみ | |
;; /n ファイルのみ | |
;; /. 拡張子指定 | |
;; /! 直前の条件の反転 | |
;; /p 直前の条件を削除 | |
;; // 全ての条件を削除 | |
(add-hook 'dired-mode-hook #'dired-filter-mode) | |
(add-hook 'dired-mode-hook #'all-the-icons-dired-mode) | |
(with-eval-after-load "dired" | |
(define-key dired-mode-map (kbd "r") 'wdired-change-to-wdired-mode) | |
;; u押下で上のディレクトリに移動 | |
(define-key dired-mode-map (kbd "u") 'dired-up-directory) | |
;; dired上のウィンドウ切り替え(左右) | |
(define-key dired-mode-map | |
(kbd "C-M-p") #'(lambda () (interactive) (other-window -1))) | |
(define-key dired-mode-map | |
(kbd "C-M-n") #'(lambda () (interactive) (other-window 1))) | |
;; ファイルサイズを読みやすくする | |
(setq dired-use-ls-dired nil) | |
(setq dired-listing-switches "-lha") | |
;; ファイルを開いているときに、カレントディレクトリをdiredで開く | |
(defun dired-find-file-current-dir () | |
"Find-file current directory" | |
(interactive) | |
(find-file default-directory)) | |
;; Dired を 2つのウィンドウで開いているときに other-window へ copy する | |
(defun dired-do-copy-dwim () | |
(interactive) | |
(let ((dired-dwim-target t)) | |
(dired-do-copy))) | |
;; Dired を 2つのウィンドウで開いているときに other-window へ move する | |
(defun dired-do-rename-dwim () | |
(interactive) | |
(let ((dired-dwim-target t)) | |
(dired-do-rename))) | |
;; Dired を 2つのウィンドウで開いているときに other-window へ symlink する | |
(defun dired-do-symlink-dwim () | |
(interactive) | |
(let ((dired-dwim-target t)) | |
(dired-do-symlink))) | |
;; dired-open-file でディレクトリ移動の際は、バッファをkill する関数 | |
(defun kill-current-buffer-and/or-dired-open-file () | |
"In Dired, dired-open-file for a file. For a directory, dired-find-file and | |
kill previously selected buffer." | |
(interactive) | |
(if (file-directory-p (dired-get-file-for-visit)) | |
(dired-find-alternate-file) | |
(dired-open-file))) | |
;; dired-up-directory で元のバッファをkill する関数 | |
(defun kill-current-buffer-and-dired-up-directory (&optional other-window) | |
"In Dired, dired-up-directory and kill previously selected buffer." | |
(interactive "P") | |
(let ((b (current-buffer))) | |
(dired-up-directory other-window) | |
(kill-buffer b))) | |
;; dired-open-file でディレクトリ移動のとき、別ウインドウに新たなバッファを作成し、 | |
;; もとのバッファを選択したままにする関数 | |
(defun dired-open-file-other-window () | |
"In Dired, open file on other-window and select previously selected buffer." | |
(interactive) | |
(let ((cur-buf (current-buffer)) (tgt-buf (dired-open-file))) | |
(switch-to-buffer cur-buf) | |
(when tgt-buf | |
(with-selected-window (next-window) | |
(switch-to-buffer tgt-buf))))) | |
;; dired-up-directory で行き先のディレクトリのバッファを別ウインドウで開く | |
(defun dired-up-directory-other-window () | |
"In Dired, dired-up-directory on other-window" | |
(interactive) | |
(dired-up-directory t))) | |
(setq eldoc-echo-area-use-multiline-p nil) ;; eldocが複数行に渡っても1行のみ表示 | |
;; Python | |
(add-hook 'python-mode-hook #'eglot-ensure) | |
(add-hook 'python-mode-hook ;; 保存時に自動整形 (eglot) | |
#'(lambda () | |
(add-hook 'before-save-hook | |
'eglot-format-buffer nil t))) | |
;; C/C++ | |
(add-hook 'c-mode-hook #'eglot-ensure) | |
(add-hook 'c++-mode-hook #'eglot-ensure) | |
(add-hook 'c-mode-common-hook | |
#'(lambda () | |
(c-set-style "GNU") | |
(setq c-basic-offset 4) ;; width of indent | |
(setq fill-column 80) | |
(setq-default auto-fill-mode t))) | |
;; https://emacs.stackexchange.com/questions/48500/how-to-clang-format-the-current-buffer-on-save | |
(defun clang-format-save-hook-for-this-buffer () | |
"Create a buffer local save hook." | |
(add-hook 'before-save-hook | |
(lambda () | |
(when (locate-dominating-file "." ".clang-format") | |
(clang-format-buffer)) | |
;; Continue to save. | |
nil) | |
nil | |
;; Buffer local hook. | |
t)) | |
;; Run this for each mode you want to use the hook. | |
(add-hook 'c-mode-hook (lambda () (clang-format-save-hook-for-this-buffer))) | |
;; yasnippet | |
(add-hook 'prog-mode-hook | |
#'(lambda () | |
(yas-minor-mode))) | |
;; recentf | |
(recentf-mode +1) | |
(setq recentf-max-saved-items 2000) | |
(defmacro with-suppressed-message (&rest body) | |
"Suppress new messages temporarily in the echo area and the | |
`*Messages*' buffer while BODY is evaluated." | |
(declare (indent 0)) | |
(let ((message-log-max nil)) | |
`(with-temp-message (or (current-message) "") ,@body))) | |
(setq recentf-auto-save-timer | |
(run-with-idle-timer 30 t #'(lambda () ;; 30秒ごとに .recentf を保存 | |
(with-suppressed-message (recentf-save-list))))) | |
(setq recentf-exclude | |
'(".recentf" "bookmarks" "^/tmp\\.*" ".gz$" "/TAGS$")) | |
;; avy カーソル移動の強化 | |
(global-set-key (kbd "C-z ;") #'avy-goto-char) | |
(global-set-key (kbd "C-c C-;") #'avy-goto-char-2) | |
(global-set-key (kbd "C-z C-p") #'avy-goto-line) | |
(define-key isearch-mode-map (kbd "C-;") 'avy-isearch) | |
(defadvice previous-line (around my-previous-line activate) | |
(cond ((eq (ad-get-arg 0) 4) | |
(avy-goto-line 1)) | |
(t | |
ad-do-it))) | |
(defadvice avy-goto-line (around my-avy-goto-line activate) | |
(let ((avy-style 'at-full)) | |
ad-do-it)) | |
;; consult 便利系コマンドの集合体 | |
(global-set-key (kbd "C-x b") #'consult-buffer) | |
(global-set-key (kbd "C-x 4 b") #'consult-buffer-other-window) | |
(global-set-key (kbd "C-x 5 b") #'consult-buffer-other-frame) | |
(global-set-key (kbd "C-x t b") #'consult-buffer-other-tab) | |
(global-set-key (kbd "C-x r b") #'consult-bookmark) | |
(global-set-key (kbd "C-z C-n") #'consult-recent-file) | |
(global-set-key (kbd "M-y") #'consult-yank-pop) | |
(global-set-key (kbd "M-g g") #'consult-goto-line) | |
(global-set-key (kbd "M-g i") #'consult-imenu) | |
(global-set-key (kbd "M-s l") #'consult-line) ;; プレビュー付きの行単位検索 | |
(global-set-key (kbd "M-s L") #'consult-line-multi) ;; 複数バッファ串刺し検索 | |
(global-set-key (kbd "M-s r") #'consult-ripgrep) ;; ripgrepによる高速検索 C-uでディレクトリ指定 | |
(define-key isearch-mode-map (kbd "M-e") #'consult-isearch-history) | |
(define-key isearch-mode-map (kbd "M-s e") #'consult-isearch-history) | |
(define-key isearch-mode-map (kbd "M-s l") #'consult-line) | |
(define-key isearch-mode-map (kbd "M-s L") #'consult-line-multi) | |
(define-key minibuffer-local-map (kbd "M-r") #'consult-history) | |
;; ;; C-uを付けるとカーソル位置の文字列を使うmy-consult-lineコマンドを定義する | |
;; (defun my-consult-line (&optional at-point) | |
;; "Consult-line uses things-at-point if set C-u prefix." | |
;; (interactive "P") | |
;; (if at-point | |
;; (consult-line (thing-at-point 'symbol)) | |
;; (consult-line))) | |
;; ;; C-s(isearch-forward)をmy-consult-lineコマンドに割り当てる | |
;; (global-set-key (kbd "C-s") 'my-consult-line) | |
;; vertico ミニバッファの入力と補完を強化 | |
(vertico-mode 1) | |
(vertico-prescient-mode 1) ;; 候補を履歴や頻度を考慮して並び替える | |
(setq vertico-cycle t) | |
;; Enable recursive minibuffers | |
(setq enable-recursive-minibuffers t) | |
;; vertico-directory | |
(define-key vertico-map "DEL" #'vertico-directory-delete-char) | |
(keymap-set vertico-map "C-l" #'vertico-directory-up) | |
;; vertico-quick | |
(keymap-set vertico-map "M-q" #'vertico-quick-insert) ;; avy-likeに候補選択してミニバッファ入力 | |
(keymap-set vertico-map "C-q" #'vertico-quick-exit) ;; avy-likeに候補選択して即時実行 | |
;; (require 'orderless) | |
;; (setq completion-styles '(orderless basic)) | |
;; (setq completion-styles '(basic partial-completion orderless)) ;; orderlessをfallbackに活用する | |
;; marginalia 補完候補のアノテーションを追加 | |
(marginalia-mode 1) | |
(define-key minibuffer-local-map (kbd "M-A") #'marginalia-cycle) | |
;; embark | |
(global-set-key (kbd "C-'") #'embark-act) | |
(global-set-key (kbd "C-\"") #'embark-dwim) | |
(with-eval-after-load 'consult | |
(with-eval-after-load 'embark | |
(require 'embark-consult))) | |
;; corfu 補完パッケージ | |
(global-corfu-mode 1) | |
(corfu-prescient-mode +1) | |
(setq corfu-auto nil) ;; t: 補完を自動で開始 | |
(setq corfu-cycle t) ;; Enable cycling for `corfu-next/previous' | |
(setq corfu-quit-at-boundary nil) ;; Never quit at completion boundary ->あいまいマッチしやすい | |
;; (setq corfu-quit-at-boundary 'separator) ;; seperatorで指定された文字でquitする | |
;; (setq corfu-quit-no-match 'separator) ;; seperatorで指定された文字はmatchから除外される ->あいまいマッチしやすい | |
;; (setq corfu-quit-no-match nil) ;; query が match しないとき "no match" 表示 | |
;; (setq corfu-quit-no-match t) ;; query が match しないとき即終了 | |
(setq corfu-separator ?\s) | |
;; Configure if the prompt or first candidate is preselected. | |
;; - prompt: Always select the prompt. | |
;; - first: Always select the first candidate. | |
;; - valid: Only select the prompt if valid and not equal to the first candidate. | |
;; - directory: Like first, but select the prompt if it is a directory. | |
(setq corfu-preselect 'valid) ;; スペース区切りであいまい入力しても補完候補で補正 | |
;; (setq corfu-preselect 'prompt) ;; 補完開始後に入力したものがそのままバッファに入る | |
(setq completion-cycle-threshold 3) ;; TAB cycle if there are only few candidates | |
;; Emacs 28: Hide commands in M-x which do not apply to the current mode. | |
;; Corfu commands are hidden, since they are not supposed to be used via M-x. | |
(setq read-extended-command-predicate #'command-completion-default-include-p) | |
;; Enable indentation+completion using the TAB key. | |
;; `completion-at-point' is often bound to M-TAB. | |
(setq tab-always-indent t) | |
;; (setq tab-always-indent 'complete) | |
;; 参考 http://blog.fujimisakari.com/elisp_useful_for_programming/ | |
(defun region-to-single-quote () | |
(interactive) | |
(quote-formater "'%s'" "^\\(\"\\).*" ".*\\(\"\\)$")) | |
(defun region-to-double-quote () | |
(interactive) | |
(quote-formater "\"%s\"" "^\\('\\).*" ".*\\('\\)$")) | |
(defun region-to-bracket () | |
(interactive) | |
(quote-formater "\(%s\)" "^\\(\\[\\).*" ".*\\(\\]\\)$")) | |
(defun region-to-square-bracket () | |
(interactive) | |
(quote-formater "\[%s\]" "^\\(\(\\).*" ".*\\(\)\\)$")) | |
(defun region-to-brace () | |
(interactive) | |
(quote-formater "\%s\]" "^\\(\(\\).*" ".*\\(\)\\)$")) | |
(defun quote-formater (quote-format re-prefix re-suffix) | |
(if mark-active | |
(let* ((region-text (buffer-substring-no-properties | |
(region-beginning) (region-end))) | |
(replace-func | |
(lambda (re target-text) | |
(replace-regexp-in-string re "" target-text nil nil 1))) | |
(text (funcall replace-func re-suffix | |
(funcall replace-func re-prefix region-text)))) | |
(delete-region (region-beginning) (region-end)) | |
(insert (format quote-format text))) | |
(error "Not Region selection"))) | |
(autoload 'consult-selected "consult-selected" nil t) | |
(autoload 'consult-line-thing-at-point "consult-thing-at-point" nil t) | |
(when (require 'selected nil t) | |
;; コメントアウト・アンコメントアウト | |
;; (define-key selected-keymap (kbd ";") #'comment-dwim-2) | |
;; 選択した関数のヘルプを表示 | |
(define-key selected-keymap (kbd "f") #'describe-function) | |
;; 選択した変数のヘルプを表示 | |
(define-key selected-keymap (kbd "v") #'describe-variable) | |
;; 選択したシンボルのヘルプを表示 | |
(define-key selected-keymap (kbd "y") #'describe-symbol) | |
;; リージョンをシングルクオートで囲う | |
(define-key selected-keymap (kbd "\'") #'region-to-single-quote) | |
;; リージョンをダブルクオートで囲う | |
(define-key selected-keymap (kbd "\"") #'region-to-double-quote) | |
;; リージョンをブラケット(カッコ)で囲う | |
(define-key selected-keymap (kbd "(") #'region-to-bracket) | |
;; リージョンをカギカッコで囲う | |
(define-key selected-keymap (kbd "[") #'region-to-square-bracket) | |
;; consult-line | |
(define-key selected-keymap (kbd "w") #'consult-line-thing-at-point) | |
;; consultインターフェイスで選択 | |
(define-key selected-keymap (kbd "l") #'consult-selected) | |
;; リージョンの文字数や単語数をカウント | |
(define-key selected-keymap (kbd "=") #'count-words-region) | |
;; 複数カーソルによるマーク | |
(define-key selected-keymap (kbd "A") #'mc/mark-all-like-this) | |
(define-key selected-keymap (kbd "n") #'mc/mark-next-like-this) | |
(define-key selected-keymap (kbd "p") #'mc/mark-previous-like-this) | |
(define-key selected-keymap (kbd "u") #'mc/unmark-next-like-this) | |
(define-key selected-keymap (kbd "U") #'mc/unmark-previous-like-this) | |
(define-key selected-keymap (kbd "s") #'mc/skip-to-next-like-this) | |
(define-key selected-keymap (kbd "S") #'mc/skip-to-previous-like-this) | |
;; 同時編集 iedit | |
;; デフォルトではバッファ全体にカーソルが分身して編集可能になるので、 | |
;; ナローイングを適宜用いる | |
(define-key selected-keymap (kbd "i") #'iedit-mode) | |
;; 有効化 | |
(selected-global-mode 1)) | |
;; ポップアップウィンドウの挙動を調整 | |
(shackle-mode 1) | |
(setq shackle-rules | |
'( | |
("*Help*" :align below :select t) | |
("*quickrun*" :align below :select t) | |
;; (" *Embark Actions*" :align right :select nil) | |
)) | |
;; ;; Command-tab的にバッファ切り替え | |
;; (setq iflipb-wrap-around t) | |
;; (setq iflipb-ignore-buffers (list "^[*]")) | |
;; ;; 切り替え対象をカレントバッファと同一のメジャーモードに限定する | |
;; (defun iflipb-major-mode-buffer-list () | |
;; "Returns list of buffers whose major-mode is the same as current buffer's one." | |
;; (let ((cur-buf-list (buffer-list (selected-frame))) | |
;; (same-major-mode-buflist nil) | |
;; (currbuf-major-mode | |
;; (buffer-local-value 'major-mode (current-buffer)))) | |
;; (dolist (buffer cur-buf-list) | |
;; (if (eq (buffer-local-value 'major-mode buffer) currbuf-major-mode) | |
;; (add-to-list 'same-major-mode-buflist buffer))) | |
;; (nreverse same-major-mode-buflist))) | |
;; (setq iflipb-buffer-list-function #'iflipb-major-mode-buffer-list) | |
;; (defhydra hydra-iflipb (global-map "C-;") | |
;; "flip buffer" | |
;; ("C-n" iflipb-next-buffer "next") | |
;; ("C-p" iflipb-previous-buffer "prev")) | |
;; neotree | |
(setq neo-show-hidden-files t) | |
(setq neo-hidden-regexp-list '("\\.pyc$" "~$" "^#.*#$" "\\.elc$")) | |
;; neotree でファイルを新規作成した後、自動的にファイルを開く | |
(setq neo-create-file-auto-open t) | |
;; conciseにするとキーバインドをシンプルにする | |
;; default | |
;; C-c C-n 作成 | |
;; C-c C-d 削除 | |
;; C-c C-r リネーム | |
;; C-c C-p コピー | |
;; concise | |
;; C ルートディレクトリ変更 | |
;; c 作成 | |
;; + 作成 | |
;; d 削除 | |
;; r リネーム | |
;; e エンター | |
(setq neo-keymap-style 'concise) | |
;; neotree ウィンドウを表示する毎に current file のあるディレクトリを表示する | |
(setq neo-smart-open t) | |
;; 幅 | |
(setq neo-window-width 20) | |
;; 自動リフレッシュ & ディレクトリ自動表示変更 | |
(setq neo-autorefresh t | |
neo-force-change-root t) | |
(add-hook 'neotree-mode-hook | |
#'(lambda () | |
(display-line-numbers-mode -1))) | |
(global-set-key [f6] #'neotree-toggle) | |
;; https://mytexpert.osdn.jp/index.php?Emacs/AUCTeX#fd84843a | |
(setq TeX-auto-save t) ; Enable parse on load. | |
(setq TeX-parse-self t) ; Enable parse on save. | |
;; (setq-default TeX-master nil) ;; 単一のtexを触る場合は特に設定せずともよい | |
;; コンパイル後に自動revert | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(add-hook 'TeX-after-compilation-finished-functions | |
#'TeX-revert-document-buffer))) | |
;; pdf-toolsと連携する場合のビューワー設定 (C-c C-v) | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(pdf-tools-install) | |
(setq TeX-view-program-selection | |
'((output-pdf "PDF Tools"))) | |
(setq TeX-view-program-list | |
'(("PDF Tools" TeX-pdf-tools-sync-view))))) | |
;; display-line-numbers-modeを使っている場合, | |
;; 不要なのでOFFにする設定はこちら | |
(add-hook 'pdf-view-mode-hook | |
#'(lambda() | |
(display-line-numbers-mode -1))) | |
;; 以下を有効にする w/ pdf-tools | |
;; - forward search (texソースから対応するPDF位置にジャンプ) | |
;; - backward search (PDFから対応するtexソースまでジャンプ) | |
;; forward search は C-c C-g | |
;; backward searchは Ctrl + 左クリック | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(setq TeX-source-correlate-method 'synctex) | |
(setq TeX-source-correlate-start-server t) | |
;; pdf-toolsと連携する場合 | |
(with-eval-after-load "pdf-sync" | |
(define-key TeX-source-correlate-map (kbd "C-c C-g") | |
'pdf-sync-forward-search)))) | |
(add-hook 'TeX-mode-hook #'TeX-source-correlate-mode) | |
;; 単にlatexmkを走らせる目的ならば以下を追記してLatexmkコマンドとして使う | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(add-to-list | |
'TeX-command-list | |
'("Latexmk" | |
"latexmk %t" | |
TeX-run-TeX nil (latex-mode) :help "Run Latexmk")))) | |
;; スペルチェック | |
(add-hook 'TeX-mode-hook #'flyspell-mode) | |
;; 数学記号まわり | |
(add-hook 'TeX-mode-hook #'LaTeX-math-mode) | |
;; 画像挿入 | |
(add-hook 'TeX-mode-hook #'auto-image-file-mode) | |
;; bibファイルのコメント開始記号 | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(setq bibtex-comment-start "%") ;backend=biber | |
;; (setq bibtex-comment-start "@Comment") ;backend=bibtex | |
)) | |
;; rextex | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(turn-on-reftex) | |
(setq reftex-plug-into-AUCTeX t) | |
(setq reftex-toc-split-windows-horizontally t) | |
(setq reftex-toc-split-windows-fraction 0.3))) | |
;; アウトラインモード (sectionやsubsectionなどの見出し確認・折りたたみ) | |
(add-hook 'TeX-mode-hook #'(lambda () (outline-minor-mode t))) | |
;; 要dvipng | |
(with-eval-after-load 'latex-math-preview | |
(setq latex-math-preview-in-math-mode-p-func | |
'latex-math-preview-in-math-mode-p) | |
(setq latex-math-preview-tex-to-png-for-preview '(platex dvipng)) | |
(setq latex-math-preview-tex-to-png-for-save '(platex dvipng)) | |
(setq latex-math-preview-tex-to-eps-for-save '(platex dvips-to-eps)) | |
(setq latex-math-preview-beamer-to-png '(platex dvipdfmx gs-to-png))) | |
;; インライン数式を入力する際、 | |
;; タイプが煩わしいのでバックスラッシュや左ブレース連打で展開できるようにしたい | |
;; →smartchrを用いて実現 | |
(when (require 'smartchr nil t) | |
(defun smartchr-keybindings-auctex () | |
(local-set-key (kbd "\\") (smartchr '("\\" "\\\\" "\\[`!!'\\]"))) | |
(local-set-key (kbd "{") (smartchr '("{`!!'}")))) | |
(add-hook 'TeX-mode-hook #'smartchr-keybindings-auctex)) | |
;; インラインプレビュー時にdvipngを用いて高速化 | |
(add-hook 'TeX-mode-hook #'(lambda () | |
(setq preview-image-type 'dvipng))) | |
;; インラインプレビュー時におけるsectionの文字化けを回避 | |
(add-hook 'TeX-mode-hook | |
#'(lambda () | |
(setq preview-default-option-list | |
'("displaymath" "floats" "graphics" | |
"textmath" "footnotes")))) | |
;; HOWM | |
(setq howm-menu-lang 'ja) | |
(setq howm-directory "~/.emacs.d/etc/howm") | |
(setq howm-list-recent-days 7) | |
(setq howm-view-split-horizontally t) | |
(autoload 'howm-menu "howm" nil t) | |
(with-eval-after-load 'howm | |
(setq howm-template | |
(concat howm-view-title-header " %title%cursor\n%date\n\n"))) | |
;; anzu | |
;; (global-anzu-mode 1) | |
(defun key-combo-after-init () | |
(require 'key-combo) | |
;; (key-combo-define-global | |
;; "C-a" '(back-to-indentation | |
;; move-beginning-of-line | |
;; beginning-of-buffer key-combo-return)) | |
;; (key-combo-define-global | |
;; "C-e" '(move-end-of-line end-of-buffer key-combo-return)) | |
(setq key-combo-python-mode-hooks '(python-mode-hook)) | |
(setq key-combo-python-default | |
'(("," . (", " ",")) | |
("=" . (" = " " == " "=")) | |
("+" . (" + " "++" " += ")) | |
("+=" . " += ") | |
("-" . (" - " "--" " -= ")) | |
("-=" . " -= ") | |
("*" . (" * " " ** ")) | |
("*=" . " *= ") | |
("/" . (" / " " // " "/")) | |
("/=" . " /= ") | |
("(" . ("(`!!')" "(")) | |
("[" . ("[`!!']" "[[`!!']]")) | |
("\"" . ("\"`!!'\"")) | |
;; ("\"" . ("\"`!!'\"" "\"\"\"`!!'\"\"\"" "\"")) | |
(">" . (" > ")) | |
("<" . (" < ")) | |
("!" . ("!" " != ")) | |
)) | |
(key-combo-define-hook key-combo-python-mode-hooks | |
'key-combo-python-load-default | |
key-combo-python-default) | |
(setq key-combo-c-mode-hooks '(c-mode-hook)) | |
(setq key-combo-c-mode-default | |
'(("," . (", " ",")) | |
("=" . (" = " " == " " === " "=")) | |
("=>" . " => ") | |
("=~" . " =~ ") | |
("+" . (" + " "++" " += " "+")) | |
("+=" . " += ") | |
("-" . (" - " " -= " "-")) | |
("-=" . " -= ") | |
(">" . (" > " " => " " >= " ">")) | |
(">=" . " >= ") | |
("%" . (" % " "%")) | |
("!" . (" != " "!")) | |
("!=" . " != " ) | |
("&" . (" & " " && " "&")) | |
("&=" . " &= ") | |
("*" . (" * " "**" "*")) | |
("*=" . " *= " ) | |
("<" . (" < " " <= " "<")) | |
("<=" . " <= ") | |
("|" . (" || " "|")) | |
("/" . (" / " "/`!!'/" "// ")) | |
("/=" . " /= ") | |
("/*" . "/* `!!' */") | |
("{" . ("{`!!'}" "{")) | |
("\"" . ("\"`!!'\"" "\"")) | |
("'" . ("'`!!''" "'")) | |
("(" . ("(`!!')" "(")))) | |
(key-combo-define-hook key-combo-c-mode-hooks | |
'key-combo-c-mode-load-default | |
key-combo-c-mode-default)) | |
(add-hook 'after-init-hook #'key-combo-after-init) | |
(add-hook 'python-mode-hook | |
#'(lambda () | |
(key-combo-mode 1))) | |
(add-hook 'c-mode-hook | |
#'(lambda () | |
(key-combo-mode 1))) | |
(add-hook 'emacs-lisp-mode-hook | |
#'(lambda () | |
(key-combo-mode 1) | |
(key-combo-load-default))) | |
(add-hook 'eshell-mode-hook | |
#'(lambda () | |
(key-combo-mode -1))) | |
(add-hook 'text-mode-hook | |
#'(lambda () | |
(key-combo-mode -1))) | |
;; eshell | |
(defun my-eshell-view-file (file) | |
"A version of `view-file' which properly respects the eshell prompt." | |
(interactive "fView file: ") | |
(unless (file-exists-p file) (error "%s does not exist" file)) | |
(let ((had-a-buf (get-file-buffer file)) | |
(buffer (find-file-noselect file))) | |
(if (eq (with-current-buffer buffer (get major-mode 'mode-class)) | |
'special) | |
(progn | |
(switch-to-buffer buffer) | |
(message "Not using View mode because the major mode is special")) | |
(let ((undo-window (list (window-buffer) (window-start) | |
(+ (window-point) | |
(length (funcall eshell-prompt-function)))))) | |
(switch-to-buffer buffer) | |
(view-mode-enter (cons (selected-window) (cons nil undo-window)) | |
'kill-buffer))))) | |
(defun eshell/less (&rest args) | |
"Invoke `view-file' on a file. \"less +42 foo\" will go to line 42 in | |
the buffer for foo." | |
(while args | |
(if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args)) | |
(let* ((line (string-to-number (match-string 1 (pop args)))) | |
(file (pop args))) | |
(my-eshell-view-file file) | |
(goto-line line)) | |
(my-eshell-view-file (pop args))))) | |
(defalias 'eshell/more 'eshell/less) | |
(defun eshell-maybe-bol () | |
(interactive) | |
(let ((p (point))) | |
(eshell-bol) | |
(if (= p (point)) | |
(beginning-of-line)))) | |
(add-hook 'eshell-mode-hook | |
#'(lambda () (define-key eshell-mode-map "\C-a" 'eshell-maybe-bol))) | |
(add-hook 'before-save-hook 'my-trailing-whitespace) | |
(defun my-trailing-whitespace () | |
(when (or (derived-mode-p 'prog-mode) (eq major-mode 'text-mode)) | |
(delete-trailing-whitespace))) | |
(custom-set-variables | |
;; custom-set-variables was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(blink-cursor-mode nil) | |
'(column-number-mode t) | |
'(package-archives | |
'(("gnu" . "https://elpa.gnu.org/packages/") | |
("melpa" . "https://melpa.org/packages/") | |
("org" . "https://orgmode.org/elpa/"))) | |
'(package-selected-packages | |
'(clang-format fzf bufferlo cape all-the-icons all-the-icons-dired dired-filter dired-narrow dired-sidebar dired-subtree mew ddskk quickrun flymake-diagnostic-at-point yasnippet-snippets key-combo orderless tempel hydra yaml-mode which-key w3m ace-link embark-consult embark marginalia pdf-tools consult-yasnippet yasnippet iflipb expand-region iedit anzu multiple-cursors howm auctex bm neotree goto-chg window-numbering perspective thingopt shackle selected vline sequential-command smart-newline undo-tree compat dash popup seq transient wgrep python-mode migemo rg mozc-temp mozc-popup mozc corfu prescient corfu-prescient vertico-prescient vertico consult avy solarized-theme leaf)) | |
'(tool-bar-mode nil)) | |
(custom-set-faces | |
;; custom-set-faces was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(default ((t (:family "Ricty Diminished" :foundry "nil" :slant normal :weight regular :height 125 :width normal)))) | |
'(yas-field-highlight-face ((t (:inherit region))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment