131 lines
4.0 KiB
EmacsLisp
131 lines
4.0 KiB
EmacsLisp
;;; init-org.el
|
|
;;; -*- lexical-binding: t -*-
|
|
|
|
(use-package org)
|
|
|
|
;; (if *is-windows*
|
|
;; (progn (run-with-idle-timer
|
|
;; 0.5 nil
|
|
;; (lambda ()
|
|
;; (with-temp-buffer
|
|
;; (org-mode)
|
|
;; (org-mode))
|
|
;; (message "Org preloaded")))))
|
|
|
|
(setq org-todo-keywords
|
|
(quote ((sequence "TODO(t)" "STARTED(s)" "|" "DONE(d!/!)")
|
|
(sequence "WAITING(w@/!)" "SOMEDAY(S)" "|" "CANCELLED(c@/!)" "MEETING(m)" "PHONE(p)"))))
|
|
|
|
(setq system-time-locale "C")
|
|
|
|
;; 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)))
|
|
|
|
(setq org-log-done t)
|
|
(setq org-log-into-drawer t)
|
|
|
|
(global-set-key (kbd "C-c a") 'org-agenda)
|
|
(setq org-agenda-files '("d:/emacs/org/learning-org-mode.org"))
|
|
(setq org-agenda-span 'day)
|
|
|
|
(setq org-capture-templates
|
|
'(("t" "Todo" entry (file+headline "d:/emacs/org/learning-org-mode.org" "Workspace")
|
|
"* TODO [#B] %?\n %i\n %U"
|
|
:empty-lines 1)))
|
|
|
|
(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
|
|
))
|
|
|
|
;; 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)
|
|
|
|
;; org tempo
|
|
;; (require 'org-tempo)
|
|
|
|
;; 批量调整表格
|
|
(defun org-table-align-all ()
|
|
"Ajust all org table in current buffer."
|
|
(interactive)
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
(org-table-map-tables 'org-table-align t)))
|
|
|
|
(provide 'init-org)
|