(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/"))
(require 'init-startup)
(require 'init-elpa)
(require 'init-org)
(require 'init-utils)
(require 'init-tools)
(require 'init-program)
(require 'init-ui)
(require 'color-rg)
(defun my-anime (year month day name)
(let* ((raw (org-cyclic 7 year month day)))
(if raw
(format "%s 第%d集" name (1+ (string-to-number (cdr raw)))))))
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment 'utf-8)
(defconst *is-windows* (or (eq system-type 'windows-nt) (eq system-type 'ms-dos)))
(defconst *is-linux* (eq system-type 'gnu/linux))
(defun open-init-file ()
"just open my init file"
(interactive)
(find-file "~/HL-emacs.d/config.org"))
(global-set-key (kbd "<f2>") 'open-init-file)
(setq custom-file "~/.emacs.d/custom.el")
(if (file-exists-p custom-file) (load custom-file))
(provide 'init-startup)
(setq package-archives '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
;; (setq package-archives '(("gnu" . "http://elpa.zilongshanren.com/gnu/")
;; ("melpa" . "http://elpa.zilongshanren.com/melpa/")))
;; mysy2 版本的 gpg 路径出问题了,先把这个关了
;;(setq package-check-signature nil)
;; (setq package-archives '(("myelpa" . "~/myelpa/")))
(require 'package)
;; (package-initialize)
(unless (bound-and-true-p package--initialized)
(package-initialize))
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-and-compile
(setq use-package-always-ensure t
use-package-always-defer t
use-package-expand-minimally t)
(require 'use-package))
(use-package diminish)
(use-package delight)
(provide 'init-elpa)
里面修改了markdown代码块导出的函数是从 这里 和 这里 抄的,做了一点小修改。 org-link参数的修改看 这里
(require 'org)
(require 'org-id)
;; org variable
(setq org-startup-truncated nil)
(setq org-log-done 'time)
(setq org-log-into-drawer t)
;; (setq org-agenda-include-diary t)
(setq system-time-locale "C")
(setq org-startup-indented t)
(setq org-image-actual-width nil)
(setq calendar-date-style 'iso)
(setq diary-show-holidays-flag nil)
(setq org-startup-folded 'content)
(setq org-clock-mode-line-total 'current)
(setq org-id-link-to-org-use-id t)
(setq org-link-parameters (delq (assoc "file+sys" org-link-parameters) org-link-parameters))
(setq org-link-parameters (delq (assoc "file+emacs" org-link-parameters) org-link-parameters))
(setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
(setq org-archive-default-command #'org-toggle-archive-tag)
;; (setq org-todo-keyword-faces '(("CANCELED" . "gray")))
;; (setq org-clock-persist 'history)
;; (org-clock-persistence-insinuate)
(add-to-list 'auto-mode-alist '("\\.txt\\'" . org-mode))
;; key bind
(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c a") #'org-agenda)
(global-set-key (kbd "C-c c") #'org-capture)
(global-set-key (kbd "C-,") #'org-cycle-agenda-files)
(define-key org-mode-map (kbd "C-c C-o") #'org-open-at-point-global)
;; org export
(require 'org-tempo)
(setq org-export-backends '(latex md html ascii org))
(defun org-mymd-example-block (example-block _content info)
"Transcode element EXAMPLE-BLOCK as ```lang ...'''."
(format "```%s\n%s```"
(org-element-property :language example-block)
(org-remove-indentation
(org-export-format-code-default example-block info))))
(advice-add 'org-md-example-block :override #'org-mymd-example-block)
;; org agenda
(setq org-agenda-files '("~/GTD/task.org"
"~/GTD/schedule.org"))
;; org-habit
(require 'org-habit)
(setq org-habit-preceding-days 10
org-habit-following-days 4)
;; org capture
(setq org-default-notes-file "~/GTD/inbox.org")
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "~/gtd/task.org" "Tasks")
"* TODO %?\n%i\n%a")
("i" "inbox" entry (file+headline "~/gtd/task.org" "inbox")
"* %?")))
(use-package org-roam
:if *is-windows*
:ensure t
:init
(setq org-roam-directory (file-truename "~/roam-note/"))
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n g" . org-roam-graph)
("C-c n i" . org-roam-node-insert)
("C-c n c" . org-roam-capture)
;; Dailies
("C-c n j" . org-roam-dailies-capture-today))
:config
;; If you're using a vertical completion framework, you might want a more informative completion interface
(setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
(org-roam-db-autosync-mode)
;; If using org-roam-protocol
(require 'org-roam-protocol))
(provide 'init-org)
(use-package company
:diminish
:defines (company-dabbrev-ignore-case company-dabbrev-downcase)
:hook (after-init . global-company-mode)
:bind (;("C-M-i" . company-complete)
("C-c i c" . company-complete)
("C-c i f" . company-files)
("C-c i y" . company-yasnippet)))
(use-package counsel
:diminish ivy-mode counsel-mode
:bind (("C-s" . swiper-isearch)
("C-r" . swiper-isearch-backward)
("M-s g" . counsel-rg)
("M-s i" . counsel-company))
:hook ((after-init . ivy-mode)
(ivy-mode . counsel-mode))
:init
(setq ivy-count-format "%d/%d "
ivy-use-virtual-buffers t
ivy-initial-inputs-alist nil))
(use-package undo-tree
:diminish
:hook (after-init . global-undo-tree-mode)
:init
(setq undo-tree-visualizer-timestamps t
undo-tree-enable-undo-in-region nil
undo-tree-auto-save-history nil))
(use-package which-key
:diminish
:hook (after-init . which-key-mode))
(use-package hungry-delete
:bind
(("C-c d" . hungry-delete-forward)
("C-c DEL" . hungry-delete-backward)))
(use-package paredit
:diminish
:hook ((lisp-mode racket-mode emacs-lisp-mode sly-mrepl-mode slime-repl-mode) . enable-paredit-mode))
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
(use-package elpa-mirror)
(use-package keyfreq
:hook ((after-init . keyfreq-mode))
:config
(keyfreq-autosave-mode 1))
(use-package expand-region
:bind ("C-=" . er/expand-region))
(use-package avy
:bind (("C-:" . avy-goto-char)
("M-g f" . avy-goto-line)
("M-g w" . avy-goto-word-1)
("M-g e" . avy-goto-word-0)
("C-'" . avy-goto-char-2)
:map org-mode-map
("C-'" . avy-goto-char-2)))
(use-package iedit
:bind ("C-;" . iedit-mode))
(provide 'init-utils)
(use-package magit
:bind (("C-x g" . magit-status)))
(use-package git-modes)
(use-package projectile
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("C-c p" . projectile-command-map)))
(use-package yasnippet
:defer nil
;; :bind
;; (("C-c y n" . yas-new-snippet)
;; ("C-c y s" . yas-insert-snippet)
;; ("C-c y v" . yas-visit-snippet-file))
:init
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
:config
(yas-global-mode 1))
(use-package yasnippet-snippets)
(use-package ivy-yasnippet
:bind (("M-s y" . ivy-yasnippet)))
(provide 'init-tools)
(use-package markdown-mode
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)))
(use-package toc-org
:hook ((org-mode markdown-mode) . toc-org-mode))
中文导出的配置抄的 这里
(use-package auctex
:if *is-windows*)
(use-package cdlatex
:if *is-windows*)
(setq-default TeX-engine 'xetex)
(require 'ox-latex)
(setq org-export-with-sub-superscripts nil)
(add-to-list 'org-latex-classes
'("ctexart"
"\\documentclass[UTF8,a4paper]{ctexart}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(setq org-latex-default-class "ctexart")
(setq org-latex-compiler "xelatex")
(setq c-default-style "bsd"
c-basic-offset 4)
(use-package sly
:init
(setq inferior-lisp-program "sbcl"))
(use-package racket-mode
:hook ((racket-mode . racket-xp-mode)))
(use-package haskell-mode)
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "-i --simple-prompt --InteractiveShell.display_page=True")
(provide 'init-program)
(use-package evil
:hook ((prog-mode text-mode) . evil-local-mode)
:init
(setq evil-undo-system 'undo-tree
evil-emacs-state-cursor 'bar
;; evil-move-beyond-eol t
evil-disable-insert-state-bindings t)
(add-hook 'evil-normal-state-entry-hook (lambda () (save-some-buffers t)))
:config
(evil-declare-key 'normal org-mode-map
(kbd "TAB") 'org-cycle))
(use-package general)
(general-evil-setup)
(general-imap "j"
(general-key-dispatch 'self-insert-command
:timeout 0.25
"k" 'evil-normal-state))
(general-define-key
:prefix "SPC"
:states '(normal visual)
"s" 'avy-goto-char-2
"t" 'org-babel-tangle
"a" 'org-agenda)
(general-define-key
:prefix ";"
:states '(normal visual)
";" 'avy-goto-char-2)
(setq default-directory "~/")
(setq delete-by-moving-to-trash t)
(setq ring-bell-function 'ignore)
(setq inhibit-splash-screen 1)
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
;; (setq make-backup-files nil)
(global-set-key (kbd "<f5>") 'revert-buffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-.") 'imenu)
;; (fset 'yes-or-no-p 'y-or-n-p)
(define-key y-or-n-p-map [return] 'act)
(setq use-short-answers t)
(add-function :after after-focus-change-function
(lambda () (save-some-buffers t)))
;; (save-place-mode 1)
(use-package delsel
:ensure nil
:hook (after-init . delete-selection-mode))
(setq inhibit-splash-screen 1)
(setq initial-scratch-message ";; Never gonna give you up ~\n\n")
(setq show-paren-delay 0
show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t)
(show-paren-mode 1)
(global-display-line-numbers-mode)
(winner-mode 1)
(column-number-mode 1)
(setq-default tab-width 4
indent-tabs-mode nil)
真的不知道该怎么设置…… 为了让 daemon 模式下字体设置也生效,就简单粗暴地直接设定 default-frame-alist 了。由于 Linux 目前上用的是 emacs-nox,所以只让这个设定在 windows 上生效。
(use-package emacs
:ensure nil
:if *is-windows*
:config
(setq-default cursor-type 'bar)
(scroll-bar-mode -1)
(tool-bar-mode 0)
(set-fontset-font "fontset-default" 'han "霞鹜文楷")
(setq default-frame-alist '((width . 90)
(height . 28)
(font . "JetBrains Mono-16")
)))
(use-package emacs
:ensure nil
:if *is-linux*
:config
(menu-bar-mode -1))
(use-package doom-themes
:if *is-linux*
:defer nil
:config (load-theme 'doom-city-lights t))
(provide 'init-ui)
最开始的方案是在bat文件里指定HOME目录 %~dp0: %0代表脚本自身,~dp表示变量扩充,d是扩充到分区,p是扩充到路径。%~dp0合起来就代表当前目录的路径。 set HOME=%~dp0
set HOME=C:\Users\<username> "C:\portable\emacs-27.2-x86_64\bin\runemacs.exe"
后来切换到守护进程(daemon)方式来运行emacs,于是设置了HOME变量并整了个ahk脚本 (此时也切换到了gccemacs,windows版本在这里下载 https://github.com/kiennq/emacs-build)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. run C:\portable\emacs-master-x86_64-full\bin\runemacs.exe --daemon, ,Hide
在守护进程运行之后,将emacsclientw.exe右键发送到桌面快捷方式,之后在 属性-目标 中加上 -c 即可
https://emacstalk.github.io/post/020/ 用这样一组参数 emacsclient -a “” -c -n “$@” 不过直接用在windows上好像有问题,把最后的 “$@” 去掉,然后创建一个快捷方式即可正常使用
这个 alias 在 linux 终端使用 alias e=”emacsclient -c -a ""”
“here”