Open58

chromebookにspacemacs環境構築

雪下雪下

chromebook (Acer Chromebook Spin 311)を購入したので、spacemacsでorg-modeを使うことを目標に環境構築を行う。

雪下雪下

linuxのインストールは設定から行える。
ついでに、検索キーとコントロールを入れ替えておく。

とりあえず最初に以下を実行。

sudo apt update
sudo apt upgrade
雪下雪下

これで、spacemacsを使って、快適な日本語入力までできるようになった。

雪下雪下

.spacemacsでフォントをNoto Sans Mono CJK JPに変更

雪下雪下

org-journalのsetup. dotspacemacs-configuration-layersに下記を追記。

     (org :variables
          ;; org-journal
          org-enable-org-journal-support t
          org-journal-dir "/mnt/chromeos/GoogleDrive/MyDrive/org/"
          org-journal-file-format "%Y-%m-%d"
          org-journal-date-prefix "#+TITLE: "
          org-journal-date-format "%Y-%m-%d"
          ;; org-journal end
          )
雪下雪下

org-journalでorg-captureを使うための設定。
https://github.com/bastibe/org-journal

layerに

org-directory "/mnt/chromeos/GoogleDrive/MyDrive/org/"

user-configに

  ;; org-journal-capture
  (defun org-journal-find-location ()
    ;; Open today's journal, but specify a non-nil prefix argument in order to
    ;; inhibit inserting the heading; org-capture will insert the heading.
    (org-journal-new-entry t)
    (unless (eq org-journal-file-type 'daily)
      (org-narrow-to-subtree))
    (goto-char (point-max)))

  (defvar org-journal--date-location-scheduled-time nil)

  (defun org-journal-date-location (&optional scheduled-time)
    (let ((scheduled-time (or scheduled-time (org-read-date nil nil nil "Date:"))))
      (setq org-journal--date-location-scheduled-time scheduled-time)
      (org-journal-new-entry t (org-time-string-to-time scheduled-time))
      (unless (eq org-journal-file-type 'daily)
        (org-narrow-to-subtree))
      (goto-char (point-max))))

  (setq org-capture-templates '(
                                ("j" "Journal entry" plain (function org-journal-find-location)
                                 "** %(format-time-string org-journal-time-format)%^{Title}\n%i%?"
                                 :jump-to-captured t :immediate-finish t)
                                ("t" "Journal task entry" plain (function org-journal-date-location)
                                 "** TODO %?\n <%(princ org-journal--date-location-scheduled-time)>\n"
                                 :jump-to-captured t)
                                )
        )

雪下雪下

org-roamの設定
layerに

org-enable-roam-support t
org-roam-v2-ack t
org-roam-directory "/mnt/chromeos/GoogleDrive/MyDrive/org/"
org-roam-db-autosync-mode t
雪下雪下

TODO管理を改造と、agenda, refileの設定

;; org todo keywords
org-todo-keywords '((sequence "TODO(t)" "SOMEDAY(s)" "WAITING(w)" "|" "DONE(d)" "CANCELED(c@)"))
; org todo keywords end
          
;; org-agenda
org-agenda-files '("/mnt/chromeos/GoogleDrive/MyDrive/org") ;; 末尾のスラッシュは不要
;; org-agenda end

;; org-refile
org-refile-targets '((org-agenda-files :maxlevel . 3))
;; org-refile end

雪下雪下

org-pomodoroの音がならない?
mozcにDMiMEが反映されてない?

雪下雪下

ターミナルでmozcの設定ツールを起動してgoogle日本語入力と同じように設定する

/usr/lib/mozc/mozc_tool --mode=config_dialog
雪下雪下

org-captureで%aは起動したときに開いていたファイルを表す。これをテンプレートに追加しておく

雪下雪下

org-capture-templatesを改造

  (setq org-capture-templates '(
                                ("j" "Journal entry" plain (function org-journal-find-location)
                                 "** %(format-time-string org-journal-time-format)%^{Title}\nfrom: %a"
                                 :immediate-finish t)
                                ("t" "Journal task entry" plain (function org-journal-date-location)
                                 "** TODO %?\n<%(princ org-journal--date-location-scheduled-time)>\nadded: %U\nfrom: %a"
                                 :jump-to-captured t)
                                ("r" "reading and watching" plain (file "/mnt/chromeos/GoogleDrive/MyDrive/org/20211012125719-reading_and_watching.org")
                                 "* TODO %^{Title}\nadded: %U\nfrom: %a"
                                 :jump-to-captured t)
                                )
        )

雪下雪下

org-captureの京大型カード用テンプレート

("c" "card" plain (file "/mnt/chromeos/GoogleDrive/MyDrive/org/20211015223240-cards.org"
"* %^{Title}\nadded: %U\nfrom: %a")
雪下雪下

検索で日本語が使えない?
vimの/だけでなく、C-sでも英数入力になってしまっている

雪下雪下

気に入ったテーマ。org-modeでの色わけがカラフルで見やすい
sanityinc-tomorrow-blue

雪下雪下

上記に対応して、level 2のheadingを挿入するようテンプレートを変更

  (setq org-capture-templates '(
                                ("j" "Journal entry" plain (function org-journal-find-location)
                                 "** %(format-time-string org-journal-time-format)%^{Title}\nfrom: %a"
                                 :immediate-finish t)
                                ("t" "Journal task entry" plain (function org-journal-date-location)
                                 "** TODO %?\n<%(princ org-journal--date-location-scheduled-time)>\nadded: %U\nfrom: %a"
                                 :jump-to-captured t)
                                ("c" "card" plain (file "/mnt/chromeos/GoogleDrive/MyDrive/org/20211015223240-cards.org")
                                 "** %^{Title}\nadded: %U\nfrom: %a"
                                 :jump-to-captured t)
                                ("s" "speed card" plain (file "/mnt/chromeos/GoogleDrive/MyDrive/org/20211015223240-cards.org")
                                 "** %^{Title}\nadded: %U\nfrom: %a"
                                 :immediate-finish t)
                                 )
        )
雪下雪下

日々の単なる記録が載ると鬱陶しいので、org-drillをorg-roamの管理から外す。
現在のorgまわりの設定をここに記す。

   ;; List of configuration layers to load.
   dotspacemacs-configuration-layers
   '(
     ;; ----------------------------------------------------------------
     ;; Example of useful layers you may want to use right away.
     ;; Uncomment some layer names and press `SPC f e R' (Vim style) or
     ;; `M-m f e R' (Emacs style) to install them.
     ;; ----------------------------------------------------------------
     auto-completion
     better-defaults
     emacs-lisp
     ;; git
     helm
     ;; lsp
     ;; markdown
     multiple-cursors
     (org :variables
          org-use-speed-commands t
          org-startup-truncated nil
          ;; org-capture用に使うdirectory
          org-directory "/mnt/chromeos/GoogleDrive/MyDrive/org/"
          ;; org-capture用に使うdirectory end

          ;; org todo keywords
          org-todo-keywords '((sequence "TODO(t)" "SOMEDAY(s)" "WAITING(w)" "|" "DONE(d)" "CANCELED(c@)"))
          ;; org todo keywords end
          ;; org-agenda
          org-agenda-files '("/mnt/chromeos/GoogleDrive/MyDrive/org")
          ;; org-agenda end

          ;; org-refile
          org-refile-targets '((org-agenda-files :maxlevel . 3))
          ;; org-refile end

          ;; org-journal
          org-enable-org-journal-support t
          org-journal-dir "/mnt/chromeos/GoogleDrive/MyDrive/org"
          org-journal-file-type 'yearly ;; ファイルは1年1つ
          org-journal-file-format "j-%Y.org"
          org-journal-date-format "%Y-%m-%d, %A"
          org-journal-find-file 'find-file
          org-journal-enable-agenda-integration t
          ;; org-journal end

          ;; org-roam
          org-enable-roam-support t
          org-roam-directory "/mnt/chromeos/GoogleDrive/MyDrive/org/roam/"
          org-roam-db-autosync-mode t
          org-roam-v2-ack t
          org-roam-complete-everywhere t
	        ;; org-roam end

          ;; org-pomodoro
          org-pomodoro-finished-sound-p t
          ;; org-pomodoro end

          ;; mode line support
          spaceline-org-clock-p t
          ;; mode line support end
          )
     (shell :variables
            shell-default-height 30
            shell-default-position 'bottom)
     spell-checking
     syntax-checking
     ;; version-control
     treemacs)

   dotspacemacs-additional-packages '(
                                      mozc
                                      org-drill
                                      )

(defun dotspacemacs/user-config ()
  "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer
configuration.
Put your configuration code here, except for variables that should be set before packages are loaded."
  ;; Mozc settings
  (set-language-environment "Japanese")
  (setq default-input-method "japanese-mozc")
  (setq mozc-candidate-style 'echo-area)

  (defun mozc-start()
    (interactive)
    (set-cursor-color "blue")
    (message "Mozc start")
    (mozc-mode 1))

  (defun mozc-end()
    (interactive)
    (set-cursor-color "gray")
    (message "Mozc end")
    (mozc-mode -1))

  (bind-keys*
   ("<henkan>" . mozc-start)
   ("<muhenkan>" . mozc-end))

  (bind-keys :map mozc-mode-map
             ("q" . mozc-end)
             ("C-g" . mozc-end)
             ("C-x h" . mark-whole-buffer)
             ("C-x C-s" . save-buffer))
  ;; Mozc settings end

  ;; copy and paste
  (defun copy-to-clipboard ()
     "Copies selection to x-clipboard."
     (interactive)
     (if (display-graphic-p)
         (progn
           (message "Yanked region to x-clipboard!")
           (call-interactively 'clipboard-kill-ring-save)
           )
       (if (region-active-p)
           (progn
             (shell-command-on-region (region-beginning) (region-end) "xsel --clipboard --input")
             (message "Yanked region to clipboard!")
             (deactivate-mark))
         (message "No region active; can't yank to clipboard!")))
     )
  (defun paste-from-clipboard()
    "Pastes from x-clipboard."
    (interactive)
    (if (display-graphic-p)
        (progn
          (clipboard-yank)
          (message "graphics active")
          )
      (insert (shell-command-to-string "xsel --clipboard --output"))
      )
    )
  (evil-leader/set-key "o y" 'copy-to-clipboard)
  (evil-leader/set-key "o p" 'paste-from-clipboard)
  ;; copy and paste end

  ;; C-h
  (bind-key* "C-h" #'delete-backward-char)
  (with-eval-after-load 'company
    (bind-key "C-h" nil company-active-map))
  ;; C-h end

  ;; org-link作成用関数
  (defun to-clipboard(x)
    "与えられた文字列をクリップボードにコピーします"
    (when x
      (with-temp-buffer
        (insert x)
        (clipboard-kill-region (point-min) (point-max)))
      (message x)))

(defun file-full-path()
    "今開いているファイルの絶対パス::行数を返します"
    (if (equal major-mode 'dired-mode)
        default-directory
      (concat (buffer-file-name) "::" (number-to-string (line-number-at-pos)))))

  (defun file-full-path-org-link-to-clipboard()
    "今開いているファイルのorg linkをクリップボードにコピーします"
    (interactive)
    (to-clipboard (concat "[[" (file-full-path) "][" (file-name-nondirectory buffer-file-name) "]]")))
  ;; org-link作成用関数 end

  ;; org-capture

  ;; org-capture後にIDもつける
  (add-hook 'org-capture-mode-hook #'org-id-get-create)
  (bind-key "C-c c" 'org-capture)

  (defun org-journal-find-location ()
    ;; Open today's journal, but specify a non-nil prefix argument in order to
    ;; inhibit inserting the heading; org-capture will insert the heading.
    (org-journal-new-entry t)
    (unless (eq org-journal-file-type 'daily)
      (org-narrow-to-subtree))
    (goto-char (point-max))
    )

  (defvar org-journal--date-location-scheduled-time nil)

  (defun org-journal-date-location (&optional scheduled-time)
    (let ((scheduled-time (or scheduled-time (org-read-date nil nil nil "Date:"))))
      (setq org-journal--date-location-scheduled-time scheduled-time)
      (org-journal-new-entry t (org-time-string-to-time scheduled-time))
      (unless (eq org-journal-file-type 'daily)
        (org-narrow-to-subtree))
      (goto-char (point-max))))

  (setq org-capture-templates '(
                                ("j" "Journal entry" plain (function org-journal-find-location)
                                 "** %(format-time-string org-journal-time-format)%^{Title}\nfrom: %a"
                                 :immediate-finish t)
                                ("t" "Journal task entry" plain (function org-journal-date-location)
                                 "** TODO %?\n<%(princ org-journal--date-location-scheduled-time)>\nadded: %U\nfrom: %a"
                                 :jump-to-captured t)
                                ("c" "card" plain (file "/mnt/chromeos/GoogleDrive/MyDrive/org/roam/20211015223240-cards.org")
                                 "** %^{Title}\nadded: %U\nfrom: %a"
                                 :jump-to-captured t)
                                ("s" "speed card" plain (file "/mnt/chromeos/GoogleDrive/MyDrive/org/roam/20211015223240-cards.org")
                                 "** %^{Title}\nadded: %U\nfrom: %a"
                                 :immediate-finish t)
                                 )
        )
  ;; org-capture end
)

雪下雪下

org→markdownへの変換のためにmarkdown layerをinstall

雪下雪下

guix pull重すぎてこのPCのスペックだときついかも。一旦断念

雪下雪下

libgccjitまわりが上手くいかない。
gccのversionが8なのがよくない?chromebookにgcc-10を入れるには?

libgccjitのコンパイルは通るがsegfaultを返す