- Add EMMS music player configuration with mpv support - Refine org-mode with preload, new capture templates, and agenda setup - Update keybindings for windows, ibuffer, and org-store-link - Improve line number display settings
148 lines
4.6 KiB
EmacsLisp
148 lines
4.6 KiB
EmacsLisp
;;; init-org.el
|
||
;;; -*- lexical-binding: t -*-
|
||
|
||
(use-package org)
|
||
|
||
;; 预加载,防止windows的org-mode加载卡顿
|
||
(if *is-windows*
|
||
(progn (run-with-idle-timer
|
||
0.5 nil
|
||
(lambda ()
|
||
(with-temp-buffer
|
||
(org-mode)
|
||
(org-mode))
|
||
(message "Org preloaded")))))
|
||
|
||
;; 一些随org-mode加载的基础配置
|
||
(add-hook 'org-mode-hook
|
||
(lambda ()
|
||
(require 'org-tempo)
|
||
(org-indent-mode)
|
||
(local-set-key (kbd "C-c i") 'consult-org-heading)))
|
||
|
||
;; 设置todo关键字
|
||
(setq org-todo-keywords
|
||
(quote ((sequence "TODO(t)" "STARTED(s)" "|" "DONE(d!/!)")
|
||
(sequence "WAITING(w@/!)" "SOMEDAY(S)" "|" "CANCELLED(c@/!)" "MEETING(m)" "PHONE(p)"))))
|
||
|
||
;; 设置标题字体大小
|
||
;; (dolist (face org-level-faces)
|
||
;; (set-face-attribute face nil :height 1))
|
||
|
||
;; log默认放入drawer中
|
||
(setq org-log-done t)
|
||
(setq org-log-into-drawer t)
|
||
|
||
;; 将系统时间(星期)设为英文,防止中文乱码
|
||
(setq system-time-locale "C")
|
||
|
||
;; capture模板
|
||
(setq org-capture-templates
|
||
'(("t" "Todo" entry (file+headline "d:/emacs/org/todos.org" "Workspace")
|
||
"* TODO [#B] %?\n %i\n %U"
|
||
:empty-lines 1)
|
||
("j" "Journal" entry (file+datetree "d:/emacs/org/journal.org")
|
||
"* %?\nEntered on %U\n %i\n")))
|
||
|
||
(global-set-key (kbd "C-c o c") 'org-capture)
|
||
|
||
(setq org-agenda-custom-commands
|
||
'(("c" "important stuff"
|
||
((tags-todo "+PRIORITY=\"A\"")))
|
||
;; ...other commands here
|
||
))
|
||
|
||
;; org-contrib 和 org-checklist
|
||
(use-package org-contrib
|
||
:straight (org-contrib :type git :host github :repo "emacsmirror/org-contrib"
|
||
:depth 1))
|
||
|
||
(add-hook 'org-mode-hook
|
||
(lambda ()
|
||
(require 'org-checklist nil t)))
|
||
|
||
;; agenda相关
|
||
(global-set-key (kbd "C-c a") 'org-agenda)
|
||
(setq org-agenda-files '("d:/emacs/org/learning-org-mode.org")) ; agenda文件,目录或单个文件
|
||
(setq org-agenda-span 'day)
|
||
|
||
|
||
;; hugo
|
||
(with-eval-after-load 'org-capture
|
||
(defun org-hugo-new-subtree-post-capture-template ()
|
||
"Returns `org-capture' template string for new Hugo post.
|
||
See `org-capture-templates' for more information."
|
||
(let* ((title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title
|
||
(fname (org-hugo-slug title)))
|
||
(mapconcat #'identity
|
||
`(
|
||
,(concat "* TODO " title)
|
||
":PROPERTIES:"
|
||
,(concat ":EXPORT_FILE_NAME: " fname)
|
||
":END:"
|
||
"\n\n") ;Place the cursor here finally
|
||
"\n")))
|
||
|
||
(add-to-list 'org-capture-templates
|
||
'("h" ;`org-capture' binding + h
|
||
"Hugo post"
|
||
entry
|
||
;; It is assumed that below file is present in `org-directory'
|
||
;; and that it has a "Blog Ideas" heading. It can even be a
|
||
;; symlink pointing to the actual location of all-posts.org!
|
||
(file+headline "d:/emacs/hugo/this-is-my-blog/all-blog.org" "Blog Ideas")
|
||
(function org-hugo-new-subtree-post-capture-template))))
|
||
|
||
;; 快速部署
|
||
(defun my-blog-publish ()
|
||
"publish blog , git add/commit/push , generate commit message"
|
||
(interactive)
|
||
(let* ((blog-dir "d:/emacs/hugo/this-is-my-blog/")
|
||
(timestamp (format-time-string "%Y-%m-%d %H:%M:%S"))
|
||
(default-directory blog-dir))
|
||
|
||
;; save buffer
|
||
(save-buffer)
|
||
|
||
;; git add
|
||
(message "Adding files...")
|
||
(eshell-command "git add .")
|
||
|
||
;; git commit with timestamp
|
||
(message "Committing: %s" timestamp)
|
||
(eshell-command (format "git commit -m \"Update: %s\"" timestamp))
|
||
|
||
;; git push
|
||
(message "Pushing to remote...")
|
||
(let ((exit-code (eshell-command "git push")))
|
||
(if (eq exit-code t)
|
||
(message "Push may have failed or nothing to push, check *Messages* buffer for details")
|
||
(message "Push successfully %s" timestamp)))))
|
||
|
||
(global-set-key (kbd "C-c o p") 'my-blog-publish)
|
||
|
||
;; 预览博客
|
||
(defun my-blog-preview ()
|
||
(interactive)
|
||
(save-buffer)
|
||
(let ((default-directory "d:/emacs/hugo/this-is-my-blog/"))
|
||
;; 启动 Hugo server
|
||
(start-process "hugo-server" "*hugo-server*"
|
||
"hugo" "server" "-D" "--bind" "0.0.0.0" "--port" "1313")
|
||
;; 等待服务器启动
|
||
(sleep-for 2)
|
||
;; 自动打开浏览器
|
||
(browse-url "http://localhost:1313")))
|
||
|
||
(global-set-key (kbd "C-c o v") 'my-blog-preview)
|
||
|
||
;; 批量调整表格
|
||
(defun org-table-align-all ()
|
||
"Ajust all table in current buffer."
|
||
(interactive)
|
||
(save-excursion
|
||
(goto-char (point-min))
|
||
(org-table-map-tables 'org-table-align t)))
|
||
|
||
(provide 'init-org)
|