転載・引用について

ユーザ用ツール

サイト用ツール


userapps:emacs

Emacs

まくら 

Emacsはとても古いEditor実装である。自分がEmacsを利用し始めたのは、高校生の時代にX68000を使っていた頃のはず。PC8801-mk2SRの次に入手したのがX68000だったとおもう。

それまでもPCは使っていた。88の頃は主にゲームばかり。X68000を手に入れてパソコン通信のChatにはまり、PC9801LVを入手してBBSサーバーにしたりはしていたが、普段使いのComputerはX68000だったと思う。

プログラムを書くようになって最初に手に馴染んだEditorはμEmacsだった。X68000でmicro Emacsを使い始めたのが最初だったと思う。そこからNEmacsに移り、Muleに移り、icam版GNU Emacsに移っていった。当時、TeXにがっつりハマり、pTeX(pLaTeXではない)で縦書き3段組の同人誌を作ったりもしていた。EmacsでTeX modeが非常に便利だったことを覚えている。

それ以来EditorといえばEmacs系のものを利用している。浪人時代に、中古で買ったSony NEWS(NEWS 1250, NEWS830, NEWS 3860)でThin EthernetでNetworkを組み、X68000をSerial Terminal にしてみたり、大学でSun MicrosystemsのSPARCstation 5, 10, IPC, IPX あたりを利用していたが、その時もEditorは常にEmacsだった。

大学時代から、Unix System管理者としては、当然にed, ex, viを「最小限」使っていた。「viはEmacsをCompileするためのpatch適用のためのEditorでしょ」なんてイキがっていたこともあった。要するに、EmacsのKey Bindingsに体が馴染んでおり、他のEditorに引っ越すことができなかっただけだろう。当然、秀丸、Vzなど様々なEditorを触ってきたし、なんとなれば EcripsやVisualStudioなどのIDEも利用したことはあるが、やはりEmacsに戻ってきてしまった。

社会人になっても、Reportや提出書類の大半はTeXを利用していた(WYSIWYGなんて面倒で不便と思っていた。今でもそう思うことは多い)ので、2000年代前半まではEmacs/TeXでほとんどの文書を処理していたし、WordやExcelを使わざるを得ない場合は、同僚のPCで処理させてもらうという悪逆非道なことをしていた。しかし、仕事の関係でどうしてもExcelやPowerPoint/KeyNoteを利用することがメインになったため、しばらく(15年くらい)ほとんどEmacsを利用していなかった。

最近またEmacsに戻ってきたので、備忘録も兼ねてEmacsの設定などを記載することにした。

マクラが長い。しかも割と黒歴史だったorz...
  • 2024/11/07
    • Updated for emacs-plus@31
    • Remove poll(Removed from emacs-plus because poll causes problem
    • install after commandline, add sign.

環境とInstall

2024年現在、メイン端末はMacBookProで、管理しているサーバーは大半がFreeBSD(一部NetBSD, OpenBSD, AlmaLinux, Debian GNU Linux, Ubuntu, Windows11がある)である。したがって、最も利用する端末であるMacBookProにEmacsを導入しており、その他の環境では原則としてvi系のSystem標準Editorを利用している。

環境

年代 端末 CPU Memory OS
2024年 MacBookPro 16“ 2019 Intel Core-i9 64G macOS Sonoma/14.6.1
2024年 VM(XCP-ng) AMD Ryzen7 3700X 4G FreeBSD 14.1

Install

昔はSource Codeを持ってきてCompileしていたが現在では流石にBinary Packageを利用している。

macOS

MacOSの場合、IMEのInline patchを当てないとMetaコマンド系を入力する際にM-あなどとなって少し(というかだいぶ)不便なので、patchを適用する。 そのため、少し面倒な対応が必要になる。

[参考]

macOSに HomeBrew を導入し、以下の一連の流れでInstallした。

$ brew tap d12frosted/emacs-plus	# Emacs-plusのtapを追加 brew tapで取り込んでいるTapを確認できる
$ brew edit emacs-plus@31		# Emacs-plus@30 (2024年8月現在のHead) のConfigを修正
.... configuration ....
  #
  # Patches
  #

  opoo "The option --with-no-frame-refocus is not required anymore in emacs-plus@30." if build.with? "no-frame-refocus"
  local_patch "fix-window-role", sha: "1f8423ea7e6e66c9ac6dd8e37b119972daa1264de00172a24a79a710efcb8130"
  local_patch "system-appearance", sha: "9eb3ce80640025bff96ebaeb5893430116368d6349f4eb0cb4ef8b3d58477db6"
  local_patch "round-undecorated-frame", sha: "9154621f59f00d58117d199a427c5c081289fd2b691b22d9bdf27efe065f43f0"
  patch do
    url "https://raw.githubusercontent.com/takaxp/ns-inline-patch/master/emacs-head-inline.patch"
  end
.... configuration ....
$ brew install emacs-plus@31 --with-dbus --with-imagemagick --with-modern-pen-icon
$ osascript -e 'tell application "Finder" to make alias file to posix file "/usr/local/opt/emacs-plus@31/Emacs.app" at POSIX file "/Applications" with properties {name:"Emacs.app"}'
$ sudo codesign --force --deep --sign - /usr/local/opt/emacs-plus@31/Emacs.app
$ brew services start d12frosted/emacs-plus/emacs-plus@31

ここまでを実行すると、

  • /Applications FolderにEmacs.appが作成される
  • LaunchPad にEmacsアイコンが追加され、
  • 起動項目にemacsが追加され、
  • BackgroundでEmacsが起動

される。一応 Inline-patch を確認するために、一度Emacsを起動し、

  • M-x mac-ime-toggle
  • M-x mac-ime-activate
  • M-x mac-ime-deactivate

が動作するかを確認しておく。

なお、自明だが、ImageMagickやDBUSを利用する場合には、brew install imagemagick dbusを実行しておくこと。

このIME用 Inline-Patchを適用した場合、init.elに以下のelisp codeを追加しておくと良い。

(when (and (memq window-system '(ns nil))
           (fboundp 'mac-get-current-input-source))
  (when (version< "27.0" emacs-version)
    ;; Required for some cases when auto detection is failed or the locale is "en".
    (custom-set-variables
     '(mac-default-input-source "com.google.inputmethod.Japanese.base")))
  (mac-input-method-mode 1))

Emacs install時の引数に –with-x11 を追加すると、Compileに失敗した(@2024/08/15)

–with-imagemagickをつけてCompile/Installすると、mu4eを利用している時に画像などが綺麗に出力されるので、余裕があるなら入れておくほうが良い。
–with-dbusをつけてCompile/Installすると、Process間通信のMessage BUSとしてDBUSを利用する。

https://github.com/d12frosted/homebrew-emacs-plus/issues/742
ここにあるように、macOS Sequoiaにおいて、Xcode commandline tools を最新にすると、Emacs.appを実行できない。
sudo codesign –force –deep –sign - /usr/local/opt/emacs-plus@31/Emacs.app
によってApp FileをSignすると実行できるようになる。注意すること

Reading directory: Operation not permitted エラーが出て、Emacsからフォルダが開けない場合
macOS SequoiaでEmacsをInstallした後、どうしてもDesktop FolderをEmacsから開けなかった。
こういう時は、一度フルディスクアクセス設定を削除したのち、もう一度フルディスクアクセス設定を行うことで回避できる可能性がある。
Commandlineから sudo tccutil reset All org.gnu.Emacs を実行し、システム環境設定からセキュリティ→フルディスクアクセスに移動し、左下の「+」からEmacs.appを追加。その後、Emacs.appを再度起動すると、Desktopフォルダにアクセスできるようになった。

FreeBSD

自分はFreeBSDをサーバーとして利用しており、GUIを利用していない。そのため、EmacsをX11経由ではなくConsoleから利用している。ほとんどの接続がssh経由だからこれでよい。

したがって、EmacsのInstallは

$ doas pkg install emacs-nox		# sudoでもよい

で終わりである。

初期設定

Emacsはそれ単体では最小限のことしかできない。しかし、Emacs-Lispを組み込み、設定を行うことで色々なことができるようになる。これを称して、昔は、「EmacsはEditorではない。Environmentである」などとも言われていた。

以下、個人の設定。 (2024/08/26)

ここで、Packageごとの設定など、細かいことを説明すればいいんだろうけど、かなり面倒なので、コメントで勘弁して。

このinit.elは、byte-compileするとgo-translate関連の変数が未定義扱いになる。 本来は:customで設定すべきなんだろうと思うがうまく行かなかったので、とりあえずは:configで逃げてある。

init.el
;;;; .emacs.d/init.el --- My init.el  -*- lexical-binding: t; -*-
;;;;
;;;; last updated: 2024/08/26
;;;; Author: HEO SeonMeyong <seirios@seirios.org>
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Tips
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; emacs -nw -q --batch --eval '(message system-configuration-options)'	; Emacs compile option(Commandline)
;; emacs --batch -f batch-byte-compile init.el				; init.elの文法チェック(init.elcは削除すること)
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Prefix keys memo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C-? : Control+?
;; M-? : Meta(ESC)+?
;; s-? : Super(command)+?
;; S-? : Shift+?	(本当?)
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; コメント定義
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; セミコロン 4 つはファイルヘッダのコメント
;; セミコロン 3 つは段落コメント
;; セミコロン 2 つはコードブロックコメント
;; セミコロン 1 つは、行コメント
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Reference site
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; https://emacs-jp.github.io						; 日本のEmacsユーザーのためのハブサイト
;;   https://emacs-jp.github.io/tips/emacs-in-2020			; * 2020年代のEmacs入門
;; https://qiita.com/conao3/items/347d7e472afd0c58fbd7			; * Emacs入門から始めるleaf.el入門
;; https://qiita.com/conao3/items/dc88bdadb0523ef95878			; * leaf.elで「init.el」をクリーンにする
;; https://uwabami.github.io/cc-env/Emacs.html				; Emacs の設定
;; https://zenn.dev/zenwerk/scraps/b1280f66c8d11a			; Emacs設定記 2021
 
;;;; PATH settings
;; elispのload-path
(setq load-path
      (append
       (list
        (expand-file-name "/usr/local/share/emacs/site-lisp")
        (expand-file-name "~/.emacs.d/elisp/")
       )
       load-path))
;; Infoのload-path
(add-to-list 'Info-default-directory-list "/usr/local/share/info/")
 
;; Magic File Nameを一時的に無効化
(defconst my:saved-file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
(add-hook 'emacs-startup-hook
          (lambda ()
            (setq file-name-handler-alist my:saved-file-name-handler-alist)))
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Package Management system
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;; Package initialization		; 2024/08/15
;;					; 2024/08/26	Modified for leaf
(eval-and-compile
  (custom-set-variables
   '(package-archives '(("gnu"   . "https://elpa.gnu.org/packages/")
                        ("melpa" . "https://melpa.org/packages/")
                        ("org"   . "https://orgmode.org/elpa/")
                        ))
   '(package-gnupghome-dir (expand-file-name ".gnupg" (getenv "HOME"))))
  (package-initialize)
  ;; leaf initialization		; 2024/08/26
  (unless (package-installed-p 'leaf)
    (package-refresh-contents)
    (package-install 'leaf t))
  (leaf leaf-keywords
    :ensure t
    ;; :init
    ;; (leaf blackout :ensure t)
    ;; (leaf hydra    :ensure t)
    ;; (leaf el-get   :ensure t)
    :config
    (leaf-keywords-init)
    )
  (setq custom-file (expand-file-name "~/.emacs.d/custom.el"))
  )
;(eval-when-compile
;  (package-refresh-contents)
;  )
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Emacs settings for Emacs base
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;;; Start-up settings
;;; EmacsのC言語部分で定義されている変数をcustomで扱えるようにまとめる
;;; 					2024/08/22			; leaf対応
(leaf cus-start
  :doc "define customization properties of builtins"
  :tag "builtin" "internal"
  :bind (("M-%"     . 'replace-regexp)			; 正規表現置換
         ("C-c M-%" . 'query-replace-regexp)		; 正規表現置換(確認)
         ("C-%"     . 'replace-string)			; 置換
         ("C-c C-%" . 'query-replace)			; 置換(確認)
         ("C-z"     . 'undo)				; Ctrl-zをminimizeからundoにremap
         ("C-x c"   . 'browse-url-at-point)		; カーソルのある地点のURLをBrowser表示
         ("C-h"     . 'delete-backward-char)		; ^h をBackspaceに設定する
         ("C-c C-l" . 'toggle-truncate-lines)		; 折り返し表示ON/OFF
         ("C-c /"   . 'comment-or-uncomment-region)	; 選択範囲をコメントアウト・コメントインする
         ("C-c l"   . 'display-line-numbers-mode)	; 左側に行番号を表示する
         ;; Mail process
         ("C-x m"   . 'mu4e)				; Mailerとしてmu4eを起動
         ;; Tab Control like Mac Window and tab control
         ("s-}"     . 'tab-bar-switch-to-next-tab)	; 次(右)のTabに移動
         ("s-{"     . 'tab-bar-switch-to-prev-tab)	; 前(左)のTabに移動
         ("s-T"     . 'tab-new)				; 新規Tabを開く
         ("s-w"     . 'tab-close)			; 現在のTabを閉じる
         ;; Search Dictionary from Dictionaly App on macOS
         ("C-c w o" .
          (lambda () (interactive)
            (let ((url (concat "dict://" (read-from-minibuffer "" (current-word)))))
              (browse-url url))))		; 辞書検索(カーソルのある位置の単語)
         ("C-c w s" .
          (lambda (key) (interactive "MSearch: ")
            (let ((url (concat "dict://" key)))
              (browse-url url))))		; 辞書検索(指定)
         )
  :hook ((minibuffer-setup-hook . shrink-window-if-larger-than-buffer)	; mini-buffer resized to contents.
         )
  :custom '((create-lockfiles . nil)					; Lockfileを作成しない
            (debug-on-error . t)					; Error時、Debuggerを起動し、backtraceを表示する
            (frame-resize-pixelwise . t)
            (enable-recursive-minibuffers . t)
            (history-length . 1000)
            (history-delete-duplicates . t)
            (scroll-preserve-screen-position . t)
            (scroll-conservatively . 101)				; 一気にscrollした場合の挙動変更(カーソルをCentralizeしない)
            (visible-bell . t)
            ;;(ring-bell-function . 'ignore)
            (text-quoting-style . 'straight)
            (truncate-lines . t)
            (tab-width . 8)						; TAB幅を8文字にする
            (line-number-display-limit-width . 10000)			; 行番号を10000行まで表示する
            (resize-mini-windows . t)					; mini-buffer auto-resize
            (max-mini-window-height . 0.1)				; mini-buffer max height to 10%
            (indicate-empty-lines . t)					; 空行を表示する
            (indicate-buffer-boundaries . 'left)			; 空行表示を左側フリンジに表示
            (scroll-step . 1)						; scrollする際のscroll行数
            (scroll-conservatively . 1)					; scrollさせる条件
            (create-lockfiles . nil)					; Lock fileを作成しない
            (gc-cons-percentage . 0.2)
            (gc-cons-threshold . 134217728)				; GC実行条件(Memory使用量)を変更する(default: 800000), 128*1024*1024
            ;; (use-dialog-box . nil)
            ;; (use-file-dialog . nil)
            (menu-bar-mode . t)						; menu-barを表示(Macの場合、MacのMenu-barに表示される)
            (tool-bar-mode . nil)					; tool-barを非表示
            (scroll-bar-mode . nil)					; scroll-barを非表示
            (indent-tabs-mode . nil)					; IndentにTabを利用しない
            (linum-mode . t)						; 行数を表示する
            (transient-mark-mode . t)					; マーク領域を色付け
            (tab-bar-mode . t)						; Tab-barを表示
            )
  :config
  (add-function :after after-focus-change-function #'garbage-collect)	; focusが外れたらGCを実行する
  (defalias 'yes-or-no-p 'y-or-n-p)
  (set-display-table-slot standard-display-table 0 ?\ )			; 文字が画面から飛び出る時にでる$マークを表示させない。
  (set-display-table-slot standard-display-table 'wrap ?\ )		; 改行の時にバックスラッシュを表示させない
  (leaf cus-start-mac
    :when (eq system-type 'darwin)					; for macOS
    :custom
    (ns-alternate-modifier . 'meta)					; Macのoptionをメタキーにする
    (ns-use-srgb-colorspace . t)					; Use sRGB
    ))
 
(leaf dired
  :bind (:dired-mode-map
         ("u" . dired-up-directory))
  )
 
;;; language/mule			2024/08/21
;;; 多言語環境における基本コマンド
(leaf mule
  :doc "basic commands for multilingual environment"
  :tag "mule" "multilingual" "character set" "coding system"
  :config
  (set-language-environment 'Japanese)					; 言語設定を日本語に
  ;; Set coding systems to UTF-8					; Coding systemをUTF-8にする
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  (set-buffer-file-coding-system 'utf-8)
  (set-file-name-coding-system 'utf-8)
  (set-clipboard-coding-system 'utf-8)
  (prefer-coding-system 'utf-8)
  (set-default buffer-file-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (leaf language-mac
    :when (eq system-type 'darwin)					; for macOS
    :custom
    (default-input-method . "macOS")					; IMをOS-X形式にする
    ))
 
;;; GUI Settings			; 2024/08/23
;;; Window systemを利用している場合の設定
(when (memq window-system '(x mac ns))					; X11/macOS/nsの場合、frame設定を適用
  ;; frame settings
  (defvar my-frame-parameters						; frame設定
    '((height        .  45)						; Size of Frame Height(Characters)
      (width         . 180)						; Size of Frame Width(Characters)
      (top           .  20)						; Position of Top(Y axis)
      (left          .  20)						; Position of left(X axis)
      (line-spacing  .   0)						; 文字間隔
      (left-fringe   .  12)						; 左側フリンジ幅
      (right-fringe  .  12)						; 右側フリンジ幅
      (cursor-type   . box)						; カーソル種別
      (alpha         .  95)						; 不透明度
      (foreground-color . "#F2F2F2")					; 文字色
      (background-color . "#000040")					; 背景色
      (cursor-color     . "#C0C000")					; カーソルの色
      (mouse-color      . "#8D8D8D")					; マウスカーソルの色
      ))
  (setq default-frame-alist my-frame-parameters)
  (setq frame-title-format '(multiple-frames "%b" ("" invocation-name)))
  ;; frame.el
  (setq blink-cursor-mode t)						; カーソルを点滅させる
  (setq frame-inherited-parameters '(font tool-bar-lines))		; C-x 5 2 で新フレームを作ったときに同じフォントを使う
 
  ;; ns-win.el
  ;; lisp side of interface with NeXT/Open/GNUstep/macOS window system
  (setq ns-pop-up-frames nil)						; 複数ウィンドウを禁止する
 
  ;; face settings / FontFace settings for mac
  (when (memq window-system '(mac ns))
    (global-set-key [s-mouse-1] 'browse-url-at-mouse)
    (let* ((size 16)
           (jpfont "PlemolJP")						; from HomeBrew/16
           ;; (jpfont "Cica")						; from HomeBrew/18
           ;; (jpfont "UD Digi Kyokasho N-R")
           ;; (jpfont "MigMix 2M")
           (asciifont "PlemolJP")					; from HomeBrew/16
           ;; (asciifont "Cica")					; from HomeBrew/18
           ;; (asciifont "UD Digi Kyokasho N-R")
           ;; (asciifont "MigMix 2M")
           (h (* size 10)))
      (set-face-attribute 'default nil :family asciifont :height h)
      (set-fontset-font t 'katakana-jisx0201 jpfont)
      (set-fontset-font t 'japanese-jisx0208 jpfont)
      (set-fontset-font t 'japanese-jisx0212 jpfont)
      (set-fontset-font t 'japanese-jisx0213-1 jpfont)
      (set-fontset-font t 'japanese-jisx0213-2 jpfont)
      (set-fontset-font t '(#x0080 . #x024F) asciifont))
    ;; Rescale the font face
    (setq face-font-rescale-alist
          '(("^-apple-hiragino.*" . 1.2)
            (".*-Hiragino Maru Gothic ProN-.*" . 1.2)
            (".*osaka-bold.*" . 1.2)
            (".*osaka-medium.*" . 1.2)
            (".*courier-bold-.*-mac-roman" . 1.0)
            (".*monaco cy-bold-.*-mac-cyrillic" . 0.9)
            (".*monaco-bold-.*-mac-roman" . 0.9)
            ("-cdac$" . 1.3)))
    ;; Check font
    ;; 1lIi / Oo0
    ;;        
 
    ;; mouse.el, mwheel.el		2024/08/21
    ;; マウス制御
    (setq mouse-drag-copy-region t)					; mouseでのDrag and Dropを許可
    ;; mwheel.el			2024/08/24
    (setq
     mouse-wheel-scroll-amount '(1 ((shift) . 2) ((control)))		; ホイールでスクロールする行数を設定
									; 1行, s[whl] 2行, C[whl] Page
     mouse-wheel-progressive-speed nil)					; wheel速度を無視
    )
  )
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Built-in eLisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;;; which-func.el			2024/08/21
;;; modelineに現在行の関数名を表示
(leaf which-function
  :doc "print current function in mode line"
  :tag "mode-line" "imenu" "tools"
  :custom ((which-function-mode . 1)					; 現在ポイントがある関数名をモードラインに表示
           ))
 
;;; time				2024/08/21
;;; modelineに時刻を表示する
(leaf time
  :doc "display time, load and mail indicator in mode line of Emacs"
  :tag "mode-line"							; not defined by time.rl
  :hook (emacs-startup-hook . display-time-mode)
  :custom ((display-time-interval . 1)					; 時刻を1秒毎に更新(default:60s)
           (display-time-string-forms . '((format "%s:%s:%s" 24-hours minutes seconds)))
                                                                        ; 時刻表示のフォーマット指定
           (display-time-day-and-date . t)				; 時刻表示を許可
           ))
 
;;; browse-url.el			2024/08/21
;;; Cursor位置のURLをSystem Browserで表示する
(leaf browse-url
  :doc "pass a URL to a web browser"
  :tag "hypertext" "hypermedia" "mouse"
  :custom ((browse-url-browser-function . 'browse-url-generic)
           )
  :config
  (leaf browse-url-mac
    :when (eq system-type 'darwin)					; for macOS
    :custom ((browse-url-generic-program . "open")			; System Browser Open command
             )))
 
;;; time-stamp				2024/08/20
;;; 					2024/08/21			; leaf対応
;;; Last Updateを更新する
(leaf time-stamp
  :doc "Maintain last change time stamps in files edited by Emacs"
  :tag "tools"
  :hook (before-save-hook . time-stamp)
  :custom ((time-stamp-active . t)  ; timestampを利用する
           (time-stamp-start . "last updated: ")			; timestamp開始文字
           (time-stamp-format . "%Y/%02m/%02d") 			; timestampのフォーマット
           (time-stamp-end . " \\|$")					; timestamp終了文字 (コメントアウト)
           ))
 
;;; Completion / ido-mode		2024/08/17
;;; 					2024/08/20			; leaf対応
;;; ファイル名補完など
;; (leaf ido
;;   :doc "interactively do things with buffers and files"
;;   :tag "extensions" "convenience"
;;   :init
;;   (ido-mode t)							; バッファやファイルの移動時に部分一致での検索を行えるようにする
;;   :custom ((ido-enable-flex-matching . t)				; 中間/あいまい一致
;;            ))
 
;;; Emacs EasyPG Assistant (EPA)	2024/06/30
;;; 					2024/08/20			; leaf対応
;;; 					2024/08/21			; pinentry対応(gpg-agent設定が必要)
;;; 	Support GPG encryptiom & decryption
(leaf epa-file
  :doc "the EasyPG Assistant, transparent file encryption"
  :tag "PGP" "GnuPG"
  :require t
  :config
  (epa-file-enable)
  (leaf epg-config.el
    :doc "configuration of the EasyPG Library"
    :tag "PGP" "GnuPG"
    :custom ((vepg-pinentry-mode . 'loopback)				; GPGのpinentryモードをloopbackに設定
             (auth-source-forget-all-cached)				; すべてのキャッシュされた認証情報を忘れる
             )))
 
;;; Whitespace-mode (minor-mode)	2024/07/02
;;; 					2024/08/21			; leaf対応
;;; White spaceのHandling
(leaf whitespace
  :doc "minor mode to visualize TAB, (HARD) SPACE, NEWLINE"
  :tag "data" "text"
  :require t
  :hook (find-file-hook . (lambda () (whitespace-mode t)))		; ファイルを開いた時にwhitespace-modeを設定する
  :custom ((whitespace-style . '(face					; faceで可視化
                                 trailing				; 行末
                                 tabs					; タブ
                                 empty					; 先頭/末尾の空行
                                 spaces					; 空白
                                 ;;space-mark				; 表示のMapping
                                 ;;tab-mark				; TABのMapping
                                 ))
           (whitespace-space-regexp . "\\(\u3000+\\)")			; 全角スペースのみを可視化
           )
  :config
  (set-face-foreground 'whitespace-space nil)
  (set-face-background 'whitespace-space "blue3")
  (set-face-attribute 'whitespace-trailing nil
                      :foreground "DeepPink"
                      :background "Perple4"
                      :underline t)
  (set-face-attribute 'whitespace-tab nil
                      :foreground "RoyalBlue4"
                      :background "gray20"
                      :underline t)
  (set-face-attribute 'whitespace-space nil
                      :background "blue3"
                      :foreground "GreenYellow"
                      :weight 'bold
                      :underline t)
  (set-face-attribute 'whitespace-empty nil
                      :foreground "MediumPurple4"
                      :background "thistle4"
                      :underline t)
  (global-whitespace-mode t)						; Whitespace-modeを全てのmodeで有効化
  )
 
;;; paren				2024/08/21
;;; highlight matching paren
(leaf paren
  :doc "highlight matching paren"
  :tag "languages" "faces"
  :hook (emacs-startup-hook . show-paren-mode)
  :custom ((show-paren-delay . 0)					; 範囲表示の遅延を0秒にする(default:0.125s)
           (show-paren-style . 'mixed)					; ウィンドウ内に収まらないときだけ、カッコ内を光らせる
           ))
 
;;; simple				2024/08/21
;;; 基本的な編集コマンド
(leaf simple
  :doc "basic editing commands for Emacs"
  :tag "Internal"
  :custom ((kill-ring-max . 100)
           (kill-read-only-ok . t)
           (kill-whole-line . nil)
           (eval-expression-print-length . nil)
           (eval-expression-print-level . nil)
           (indent-tabs-mode . nil)					; タブにTABを使用する
           (size-indication-mode . t)					; File Sizeを表示する
           (column-number-mode . t)					; 列数を表示する
           (mail-user-agent . 'mu4e-user-agent)				; default mail client to mu4e
           ))
 
;;; files				2024/08/21
;;; file操作関連・特にbackup関連設定
(leaf files
  :doc "file input and output commands for Emacs"
  :tag "none"								; Not defined by files.el
  :custom (
           (make-backup-files . t)					; バックアップファイルを作成させる
           (backup-by-copying . t)					; バックアップファイル作成時、元ファイルをCopy
           (version-control . t)					; 実行の有無
           (kept-new-versions . 2)					; 最新の保持数
           (kept-old-versions . 2)					; 最古の保持数
           (delete-old-versions . t)					; 範囲外を削除
           (auto-save-timeout . 15)					; オートセーブのtimeout時間(s)
           (auto-save-interval . 60)					; オートセーブの頻度(s)
           (delete-auto-save-files . t)					; 終了時にオートセーブファイルを削除する
           ;; (auto-save-file-name-transforms . '((".*" ,(locate-user-emacs-file "backup/") t)))
           ;; (backup-directory-alist . '((".*" . ,(locate-user-emacs-file "backup"))
           ;;                             (,tramp-file-name-regexp . nil)))
									; backupとauto-saveファイルは.emacs/backupにおく
           ))
 
;;; startup				2024/08/21
(leaf startup
  :doc "process Emacs shell arguments"
  :tag "internal"
  :custom `((init-file-debug . t)					; init.elをdebugする
            (auto-save-list-file-prefix . ,(locate-user-emacs-file "backup/.saves-"))
									; auto-save listの設定をする(files参照)
            (inhibit-startup-screen . t)				; スタートアップ画面を表示させない
            (inhibit-startup-message . t)				; スタートアップメッセージを表示させない
            (inhibit-startup-echo-area-message . t)			; スタートアップ時、echoエリアメッセージを表示させない
            (initial-scratch-message . "")				; *scratch* バッファの初期メッセージを消す
           ))
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Additional Packages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;;; company-mode			2024/06/12
;;; 					2024/08/21			; leaf対応
(leaf company
  :doc "Modular text completion framework"
  :req "emacs-24.3"
  :tag "matching" "convenience" "abbrev" "emacs>=24.3"
  :url "http://company-mode.github.io/"
  :emacs>= 24.3
  :ensure t
  ;; :blackout t
  :leaf-defer nil
  :bind (("C-M-i" . company-complete)
         (company-active-map
          ("M-n" . nil)
          ("M-p" . nil)
          ("C-n" . company-select-next)					; 次の補完候補へ
          ("C-p" . company-select-previous)				; 前の補完候補へ
          ("C-s" . company-filter-candidates)
          ("C-h" . nil)							; C-hは無効化(BS設定)
          ("C-S-h" . company-show-doc-buffer)				; ドキュメント表示はC-Shift-h
          ("<tab>" . company-complete-common)				; 共通部分までを補完する
          )
         (company-search-map
          ("C-n" . company-select-next)
          ("C-p" . company-select-previous)
          ))
  ;; :hook (emacs-lisp-mode-hook . company-mode)			; Elisp-modeで有効
  :custom ((company-idle-delay . 0.3)					; companyが動作するまでのタイムラグ
           (company-minimum-prefix-length . 2)				; デフォルトは4
           (company-transformers . '(company-sort-by-backend-importance))	; ソート順
           ; (company-transformers . '(company-sort-by-occurrence))	; 発見(記述)順
           (company-auto-expand . t)					; 全Bufferで有効
           (company-selection-wrap-around . t)				; 候補の最後の次は先頭に戻る
           (completion-ignore-case . t)					; 補完時に大文字小文字を区別しない
           (company-dabbrev-downcase . nil)
           (company-show-numbers . t)
           )
  ;; :global-minor-mode global-company-mode
  :custom-face
  (company-tooltip
   `((t :foreground "#36c6b0" :background "#244f36")))			; 未選択項目
  (company-tooltip-common
   `((t :foreground "white"   :background "#244f36")))			; 未選択項目&一致文字
  (company-tooltip-selection
   `((t :foreground "#a1ffcd" :background "#007771")))			; 選択項目
  (company-tooltip-common-selection
   `((t :foreground "white"   :background "#007771")))			; 選択項目&一致文字
  (company-scrollbar-fg
   `((t :background "#4cd0c1")))					; スクロールバー
  (company-scrollbar-bg
   `((t :background "#002b37")))					; スクロールバー背景
  )
 
;;; lua-mode				2024/06/12
;;; 					2024/08/19			; leaf対応
(leaf lua-mode
  :ensure t
  :mode ("\\.lua\\'" . lua-mode)
  :interpreter ("lua" . lua-mode)
  :custom ((lua-indent-level . 2)					; Indent offset
           (lua-indent-string-contents . nil)				; 複数行にわたる文字列をコメント同様に字下げする
           (lua-indent-nested-block-content-align . t)			; 入れ子のブロックの内容を開括弧で揃える
           (lua-indent-close-paren-align . t)				; 閉じ括弧を行頭ではなく開き括弧に合わせる
           (lua-default-application . "/usr/local/bin/lua")		; subprocess command path
           (lua-default-command-switches . "-i")			; subprocess実行時の引数
           (lua-always-show . t))					; subprocess実行の REPL bufferを表示
  :config
  (leaf company-lua
    :ensure t
    :hook (add-hook 'lua-mode-hook 'company-mode)			; company-modeをenable
    ))
 
;;; caddyfile-mode (cnfiguration mode)	2024/08/05
;;; 					2024/08/19			; leaf対応
(leaf caddyfile-mode
  :ensure t
  :mode (("Caddyfile\\'" . caddyfile-mode)
         ("caddy\\.conf\\'" . caddyfile-mode))
  :hook (caddyfile-mode-hook . my-caddyfile-hook)
  :config
  (defun my-caddyfile-hook ()
    "Custom configurations for `caddyfile-mode`."
    (setq-local tab-width 4)						; Default: 8
    (setq-local indent-tabs-mode nil))					; Default: t
  )
 
;;; nginx mode				2024/08/05
;;; 					2024/08/19			; leaf対応
(leaf nginx-mode
  :ensure t
  :mode ("nginx\\.conf\\'" . nginx-mode)
  :hook (nginx-mode-hook . company-mode)				; company-modeを起動
  :config
  (leaf company-nginx
    :ensure t
    :hook (add-hook 'nginx-mode-hook 'company-mode)			; company-modeをenable
    ))
 
;;; w3m					2024/08/25
;;; Emacs W3m browser support.
(leaf w3m
  :ensure t
  )
 
;;; vc-fossil				2024/08/25
;;; Fossil vc backend.
(leaf vc-fossil
  :ensure t
  :init (add-to-list 'vc-handled-backends 'Fossil t)
  )
 
;;; go-translate			2024/08/25
;;; Text translator for Emacs.
;;; https://github.com/lorniu/go-translate
(leaf go-translate
  :ensure t
  :bind ("C-c t" . gt-do-translate)
  :config
  (setq gt-langs '(en ja))
  (setq gt-default-translator
        (gt-translator
         :taker   (gt-taker :text 'buffer :pick 'paragraph)		; config the Taker
         :engines (list
                   ;; (gt-bing-engine)					; Bing Translator
                   (gt-google-engine)					; Google Translator
                   (gt-deepl-engine :key "DeepLAPI-KeyX-xxxx-xxxx-secret:XX" :pro nil)
                                                                        ; DeepL Translator
                   )
         :render  (gt-buffer-render)))					; config the Render
  )
 
;;; my:deepl-translate			2024/08/25
;; Deepl translation on web page(Web経由)
(leaf my:deepl-traqslate
  :bind ("C-c T" . my:deepl-translate)
  :preface
  (defun my:deepl-translate (&optional string)
    (interactive)
    (setq string
          (cond ((stringp string) string)
                ((use-region-p)
                 (buffer-substring (region-beginning) (region-end)))
                (t
                 (save-excursion
                   (let (s)
                     (forward-char 1)
                     (backward-sentence)
                     (setq s (point))
                     (forward-sentence)
                     (buffer-substring s (point)))))))
    (run-at-time 0.1 nil 'deactivate-mark)
    (browse-url
     (concat
      "https://www.deepl.com/translator#en/ja/"
      (url-hexify-string string)
      ))))
 
;;; Specific Configuration
;;; for mu4e
(load "~/.emacs.d/mu4e-init.el")
 
(provide 'init)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; init.el ends here
 
;; Local Variables:
;; coding: utf-8
;; comment-column: 72
;; version-control: t
;; kept-old-versions: 2
;; kept-new-versions: 2
;; End:
このウェブサイトはクッキーを使用しています。 Webサイトを使用することで、あなたはあなたのコンピュータにクッキーを保存することに同意します。 また、あなたはあなたが私たちのプライバシーポリシーを読んで理解したことを認めます。 同意しない場合はウェブサイトを離れてください。クッキーに関する詳細情報
userapps/emacs.txt · 最終更新: 2025/04/06 02:25 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki