All in Emacs

GNE Emacsを、初心者の気持ちで、学びなおします。
忘れないように、備忘録として始めました。

init.el をleaf.elで書き直し(WindowsとUbuntuに両対応)(4回目修正版)

2022-06-02 03:35:07 | 日記

※前回掲載したものは、windowsのIMEが機能しなかったので、修正版として掲載します。

※OSに合わせて、日本語設定を切り替える部分をleafらしく再修正しました。

※leaf-keywordの範囲(閉じ括弧)をお手本通りに修正、パッケージにleaf-convert-insert-templateで情報(:doc、: req等)を付け加えた。文字化けがあったので日本語フォントの指定を行った。再々修正しました。

※6/2修正分

 which-keyも含めました。また、leafの定義(最初の5行)が抜けていましたので追加しました。

 

init.elをleaf.elで書き直しました。

今後のパッケージ管理は、leaf.elが主流になりそうなので、書き換えました。

あと、WindowsとUbuntu(linux系でmozcであればOK)の両方で、日本語入力ができるようになりました。

WindowsとUbuntuを判定して、日本語設定を変えるようにしています。

 


;;;; init.el
;; 動作確認:
;; Windows10 バージョン 21H2
;; Ubuntu 20.04.4 LTS Release: 20.04 
;; GNU Emacs 28.1 (build 52, x86_64-w64-mingw32) of 2022-04-05
;; 修正日: 2022.06.02 
;; tr-emacs-ime-module README.md を参照して作成
;; package、Windwos IME設定

;; 初めての package-initialize または
;; 何もパッケージがインストールされていない場合のみ
;; package.elをロードさせるため package-initialize を実行してください。

(eval-and-compile
  (when (or load-file-name byte-compile-current-file)
    (setq user-emacs-directory
          (expand-file-name
           (file-name-directory (or load-file-name byte-compile-current-file))))))


(eval-and-compile
  (customize-set-variable
   'package-archives '(("melpa" . "https://melpa.org/packages/")
                       ("melpa-stable" . "https://stable.melpa.org/packages/")
                       ("gnu"   . "https://elpa.gnu.org/packages/")))
  (package-initialize)

  (unless (package-installed-p 'leaf)
    (package-refresh-contents)
    (package-install 'leaf))

  (leaf leaf-keywords
    :doc "Additional leaf.el keywords for external packages"
    :req "emacs-24.4" "leaf-3.5.0"
    :tag "settings" "lisp" "emacs>=24.4"
    :url "https://github.com/conao3/leaf-keywords.el"
    :added "2022-05-23"
    :emacs>= 24.4
    :ensure t
    :init
    ;; optional packages if you want to use :hydra, :el-get, :blackout,,,
    (leaf hydra
      :doc "Make bindings that stick around."
      :req "cl-lib-0.5" "lv-0"
      :tag "bindings"
      :url "https://github.com/abo-abo/hydra"
      :added "2022-05-23"
      :ensure t)
    (leaf el-get
      :doc "Manage the external elisp bits and pieces you depend upon"
      :tag "emacswiki" "http-tar" "http" "pacman" "fink" "apt-get" "hg" "darcs" "svn" "cvs" "bzr" "git-svn" "git" "elpa" "install" "elisp" "package" "emacs"
      :url "http://www.emacswiki.org/emacs/el-get"
      :added "2022-05-23"
      :ensure t)
    (leaf blackout
      :doc "Better mode lighter overriding"
      :req "emacs-26"
      :tag "extensions" "emacs>=26"
      :url "https://github.com/radian-software/blackout"
      :added "2022-05-23"
      :emacs>= 26
      :ensure t)
    :config
    ;; initialize leaf-keywords.el
    (leaf-keywords-init)))

(leaf leaf
  :config
  (leaf leaf-convert
    :doc "Convert many format to leaf format"
    :req "emacs-26.1" "leaf-3.6.0" "leaf-keywords-1.1.0" "ppp-2.1"
    :tag "tools" "emacs>=26.1"
    :url "https://github.com/conao3/leaf-convert.el"
    :added "2022-05-23"
    :emacs>= 26.1
    :ensure t)

  (leaf leaf-tree
    :doc "Interactive side-bar feature for init.el using leaf"
    :req "emacs-25.1" "imenu-list-0.8"
    :tag "leaf" "convenience" "emacs>=25.1"
    :url "https://github.com/conao3/leaf-tree.el"
    :added "2022-05-23"
    :emacs>= 25.1
    :ensure t
    :custom ((imenu-list-size . 30)
             (imenu-list-position . 'left))))

(leaf macrostep
  :doc "interactive macro expander"
  :req "cl-lib-0.5"
  :tag "debugging" "macro" "languages" "lisp"
  :url "https://github.com/joddie/macrostep"
  :added "2022-05-23"
  :ensure t
  :bind (("C-c e" . macrostep-expand)))

(leaf all-the-icons
  :doc "A library for inserting Developer icons"
  :req "emacs-24.3"
  :tag "lisp" "convenient" "emacs>=24.3"
  :url "https://github.com/domtronn/all-the-icons.el"
  :added "2022-05-23"
  :emacs>= 24.3
  :when (display-graphic-p)
  :ensure t)

(leaf ime
  :config
  (set-language-environment "Japanese")
  ;; OS によって設定を切り替える
  ;; Windows 日本語設定
  (leaf windows
    :when (eq system-type 'windows-nt) ; Windows
    ;;  (setenv "PATH"  (concat "C:\\Programs\\msys64\\usr\\bin;" (getenv "PATH"))) ; msys2 の PATH 設定を追加
    ;; tr-imeのDLLを自動でダウンロードしてくれる 
    :config
    (leaf tr-ime
      :doc "Emulator of IME patch for Windows"
      :req "emacs-27.1" "w32-ime-0.0.1"
      :tag "emacs>=27.1"
      :url "https://github.com/trueroad/tr-emacs-ime-module"
      :added "2022-05-22"
      :emacs>= 27.1
      :ensure t
      :config
      (tr-ime-standard-install)
      )
     (set-language-environment "Japanese")

    ;; IM のデフォルトを IME に設定
    (setq default-input-method "W32-IME")
    ;; IME のモードライン表示設定
    (setq-default w32-ime-mode-line-state-indicator "[--]")
    (setq w32-ime-mode-line-state-indicator-list '("[--]" "[あ]" "[--]"))
    ;; IME 初期化
    (w32-ime-initialize)
    (w32-ime-wrap-function-to-control-ime 'universal-argument)
    (w32-ime-wrap-function-to-control-ime 'read-string)
    (w32-ime-wrap-function-to-control-ime 'read-char)
    (w32-ime-wrap-function-to-control-ime 'read-from-minibuffer)
    (w32-ime-wrap-function-to-control-ime 'y-or-n-p)
    (w32-ime-wrap-function-to-control-ime 'yes-or-no-p)
    (w32-ime-wrap-function-to-control-ime 'map-y-or-n-p)
    (w32-ime-wrap-function-to-control-ime 'register-read-with-preview)
   (set-frame-font "MS Gothic-12" nil t)
   (modify-all-frames-parameters
    '((ime-font . "MS Gothic-12")))
    (add-hook 'isearch-mode-hook
       (lambda nil
  (setq w32-ime-composition-window (minibuffer-window))))
    (add-hook 'isearch-mode-end-hook
       (lambda nil
  (setq w32-ime-composition-window nil)))
    )

  ;; Mac OS X 日本語設定
  ;; (leaf mac
  ;;   :when (eq system-type 'darwin) ; Mac OS X
  ;;   :config
  ;;   (exec-path-from-shell-initialize)) ; PATH 設定を引き継ぐ

  ;; linux OS 日本語設定
  (leaf linux
    :when (eq system-type 'gnu/linux) ; linux
    :config
    (leaf mozc
      :doc "minor mode to input Japanese with Mozc"
      :tag "input method" "multilingual" "mule"
      :added "2022-05-22"
      :ensure t
      :config
     (set-language-environment "Japanese")
 
     (setq default-input-method "japanese-mozc")
      (prefer-coding-system 'utf-8)
      (setq mozc-candidate-style 'echo-area)
      (setq quail-japanese-use-double-n t))
    )
  )

(leaf vertico-setting
  :config
  (leaf consult
    :doc "Consulting completing-read"
    :req "emacs-27.1" "compat-28.1"
    :tag "emacs>=27.1"
    :url "https://github.com/minad/consult"
    :added "2022-05-22"
    :emacs>= 27.1
    :ensure t
    :bind (("C-c h" . consult-history)
    ("C-c m" . consult-mode-command)
    ("C-c b" . consult-bookmark)
    ("C-c k" . consult-kmacro)
    ("C-x M-:" . consult-complex-command)
    ("C-x b" . consult-buffer)
    ("C-x 4 b" . consult-buffer-other-window)
    ("C-x 5 b" . consult-buffer-other-frame)
    ("M-#" . consult-register-load)
    ("M-'" . consult-register-store)
    ("C-M-#" . consult-register)
    ("M-y" . consult-yank-pop)
    (" a" . consult-apropos)
    ("M-g e" . consult-compile-error)
    ("M-g f" . consult-flymake)
    ("M-g g" . consult-goto-line)
    ("M-g M-g" . consult-goto-line)
    ("M-g o" . consult-outline)
    ("M-g m" . consult-mark)
    ("M-g k" . consult-global-mark)
    ("M-g i" . consult-imenu)
    ("M-g I" . consult-imenu-multi)
    ("M-s f" . consult-find)
    ("M-s F" . consult-locate)
    ("M-s g" . consult-grep)
    ("M-s G" . consult-git-grep)
    ("M-s r" . consult-ripgrep)
    ("M-s l" . consult-line)
    ("M-s L" . consult-line-multi)
    ("M-s m" . consult-multi-occur)
    ("M-s k" . consult-keep-lines)
    ("M-s u" . consult-focus-lines)
    ("M-s e" . consult-isearch)
    (isearch-mode-map
     ("M-e" . consult-isearch)
     ("M-s e" . consult-isearch)
     ("M-s l" . consult-line)
     ("M-s L" . consult-line-multi)))
    )
  (leaf orderless
    :doc "Completion style for matching regexps in any order"
    :req "emacs-26.1"
    :tag "extensions" "emacs>=26.1"
    :url "https://github.com/oantolin/orderless"
    :added "2021-09-04"
    :emacs>= 26.1
    :setq ((completion-styles quote
         (orderless)))
    :ensure t)
  
  (leaf vertico
    :doc "VERTical Interactive COmpletion"
    :req "emacs-27.1"
    :tag "emacs>=27.1"
    :url "https://github.com/minad/vertico"
    :added "2021-09-04"
    :emacs>= 27.1
    :setq ((vertico-count . 10))
    :ensure t)
  
  (leaf marginalia
    :doc "Enrich existing commands with completion annotations"
    :req "emacs-27.1"
    :tag "emacs>=27.1"
    :url "https://github.com/minad/marginalia"
    :added "2022-05-22"
    :emacs>= 27.1
    :ensure t)

  (leaf init_hook
    :preface
    (defun after-init-hook nil
      (vertico-mode)
      (marginalia-mode)
      (savehist-mode))
    :hook ((after-init-hook . after-init-hook)))
  
  (leaf embark
    :doc "Conveniently act on minibuffer completions"
    :req "emacs-26.1"
    :tag "convenience" "emacs>=26.1"
    :url "https://github.com/oantolin/embark"
    :added "2021-09-04"
    :emacs>= 26.1
    :ensure t)
  
  (leaf embark-consult
    :doc "Consult integration for Embark"
    :req "emacs-25.1" "embark-0.9" "consult-0.1"
    :tag "convenience" "emacs>=25.1"
    :url "https://github.com/oantolin/embark"
    :added "2021-09-04"
    :emacs>= 25.1
    :ensure t
    :after embark consult)
  )

(leaf which-key
  :doc "Display available keybindings in popup"
  :req "emacs-24.4"
  :tag "emacs>=24.4"
  :url "https://github.com/justbur/emacs-which-key"
  :added "2022-05-22"
  :emacs>= 24.4
  :ensure t
  :config
  (which-key-mode);; (which-key-setup-minibuffer)
  )


(provide 'init)

 



最新の画像もっと見る

コメントを投稿