Skip to content

lijigang/100-questions-about-orgmode

Repository files navigation

100-questions-about-orgmode

Demos

demo-org.png demo-eaf-rss-reader.png demo-eaf-pdf-reader.png demo-eaf-browser.png

Agenda [12/12]

  • [X] 如何设定 Agenda 文件的相对路径
    ;; 1. When a capture template specifies a target file that is not an
    ;;    absolute path.  The path will then be interpreted relative to
    ;;    org-directory
    ;; 2. When the value of variable org-agenda-files is a single file, any
    ;;    relative paths in this file will be taken as relative to
    ;;    org-directory.
    (setq org-directory "~/Documents/emacs/org/")
        
  • [X] 如何指定一个目录及其子目录中的所有 org 文件为 agenda files
    (after! org
      (setq org-agenda-files
            (directory-files-recursively
             (concat org-directory "roam") "\\.org$")))
        
  • [X] 如何设定自己的私有纪念日文件
    (after! org
      (setq diary-file
            (concat org-directory "private/standard-diary")))
    
    ;; 在standard-diary 文件中, 写下面这行, 就会在生日当天看到后面的提示语句
    ;; %%(org-anniversary 2000 1 1) I am %d years old
        
  • [X] 如何设定 Agenda view 时间显示为两位数(9:30 -> 09:30)
    (after! org
      (setq org-agenda-time-leading-zero t))
        
  • [X] 如何设定 Agenda view 默认展示区间为一周
    (after! org
    
      ;; Number of days to include in overview display.
      ;; Can be day, week, month, year, or any number of days.
      (setq org-agenda-span 7))
        
  • [X] 如何设定 Agenda view 默认从周一开始展示
    (after! org
    
      ;; 0 denotes Sunday, 1 denotes Monday, etc.
      ;; When nil, always start on the current day.
      (setq org-agenda-start-on-weekday 1))
        
  • [X] 如何关闭 Agenda view 时间分隔线
    (setq org-agenda-use-time-grid nil)
        
  • [X] 如何关闭 Agenda view 中所有 tags 的显示
    (setq org-agenda-hide-tags-regexp ".")
        
  • [X] 如何关闭 Agenda view 显示已经完成的预约事项
    (setq org-agenda-skip-scheduled-if-done t)
        
  • [X] 如何设置 Agenda view 的窗口显示?
    (setq org-agenda-window-setup 'current-window)
        
  • [X] 如何设置 Agenda view deadline 随时间紧迫程度的样式
    (setq org-agenda-deadline-faces
          '((1.001 . error)
            (1.0 . org-warning)
            (0.5 . org-upcoming-deadline)
            (0.0 . org-upcoming-distant-deadline)))
        
  • [X] 如何关闭 Agenda view 中的小时分隔线
    (setq org-agenda-use-time-grid nil)
        

Block [7/7]

  • [X] 如何在 Source Block 中像在语言 mode 中一样的缩进
    (after! org
      (setq org-src-tab-acts-natively t)
      (setq org-src-preserve-indentation nil))
        
  • [X] 如何让 code block 默认折叠展示
    (after! org
      (setq org-hide-block-startup t))
        
  • [X] 如何让 code block 折叠时显示为一个符号
    ;; learn from: https://github.com/Elilif/.elemacs
    (defun eli-hide-org-block-begin-line (orig from to flag spec)
      (if (eq spec 'org-hide-block)
          (let* ((beg-of-line (save-excursion
                                (beginning-of-line)
                                (point)))
                 (lang (car (org-babel-get-src-block-info)))
                 (beg (+ beg-of-line 12 (length lang))))
            (funcall orig beg to flag spec))
        (funcall orig from to flag spec)))
    
    (advice-add 'org-flag-region :around #'eli-hide-org-block-begin-line)
        
  • [X] 如何禁用 evaluate code block 时的确认提示
    (after! org
      (setq org-confirm-babel-evaluate nil))
        
  • [X] 如何美化 quote 和 verse block
    (setq org-fontify-quote-and-verse-blocks t)
        
  • [X] 如何使用 Plantuml
    (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
    (setq org-plantuml-jar-path (expand-file-name "~/Documents/emacs/org/private/plantuml.jar"))
    (setq plantuml-default-exec-mode 'jar)
    
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((plantuml . t)))
        
  • [X] 如何配置 block 默认参数
    (setq org-babel-default-header-args
          '((:session . "none")
            (:results . "replace")))
        

Capture [0/0]

Export [1/1]

  • [X] 如何配置导出 HTML 的样式
    (setq org-html-coding-system 'utf-8)
    (setq org-html-doctype "html5")
    (setq org-html-head
          "<link rel='stylesheet' type='text/css' href='https://gongzhitaao.org/orgcss/org.css'/> ")
        

General [1/1]

  • [X] 如何在 macOS 上粘贴图片到 Emacs
    (use-package! org-mac-image-paste
      :config
      (org-mac-image-paste-mode 1)
      )
    
        

LaTex [1/1]

  • [X] 如何直观展示 LaTeX 公式效果
    (use-package! org-fragtog
      :hook (org-mode . org-fragtog-mode))
    
        

List [2/2]

  • [X] 如何更改子 list 的显示符号
    (after! org
      (setq org-list-demote-modify-bullet
            '(("+" . "-") ("-" . "+") ("*" . "+") ("1." . "a."))))
        
  • [X] 如何更改 List 的样式
    (font-lock-add-keywords
     'org-mode
     '(("^ +\\([-*]\\) "
        (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) ""))))))
        

Move [1/1]

  • [X] 如何跳转时支持汉字拼音
    (use-package! ace-pinyin
      :config
      (ace-pinyin-global-mode +1))
        

Table [5/5]

  • [X] orgmode 的表格是否支持数据透视表 需要安装额外的 Package:

    https://github.com/tbanel/orgaggregate

    Aggregating a table is creating a new table by computing sums, averages, and so on, out of material from the first table.

  • [X] orgmode 的表格是否支持画 ascii 图形 光标放在要画图的数据列上, 然后 M-x: orgtbl-ascii-draw
    xx^3
    11:
    28Wc
    327WWWWh
    464WWWWWWWWWWW.
    5125WWWWWWWWWWWWWWWWWWWWWl
    6216WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWc
  • [X] orgmode 的表格如何中英文混排对齐
    (use-package! valign
      :config
      (setq valign-fancy-bar t)
      (add-hook 'org-mode-hook #'valign-mode))
        
  • [X] orgmode 的表格如何插入 | 竖线 参照手册link

    To insert a vertical bar into a table field, use ‘\ vert’ or, inside a word ‘abc\ vert{}def’.

  • [X] 如何不导出特定的一个表格?

    有三种方法:

    1. 方法一: 将表格置于 comment block 环境中
    2. 方法二: 将表格置于 Headline 下, 该 Headline 增加一个 :noexport: 的 tag
    3. 方法三: 在文件头的选项配置中 #+options: |:nil

Tasks [12/12]

  • [X] 如何设置默认的 TODO Keywords
    (after! org
      (setq org-todo-keywords
            '((sequence "TODO" "WORK" "|" "DONE"))))
        
  • [X] 如何给指定的文件设置特定的 TODO Keywords
    ;; 在指定文件顶部增加#+todo, 设置所需的Keywords
    #+todo: 待定(d) 安排(a) | 结束(j)
        
  • [X] 如何美化 headline bullets
    ;; 使用 org-superstar package
    (after! org-superstar
      ;; other symbols like: 🦄 🧙 🐻 "🙘" "🙙" "🙚" "🙛"
      (setq org-superstar-headline-bullets-list '( "" "" "" "")
            org-superstar-prettify-item-bullets t ))
        
  • [X] 如何在完成任务时自动打上完成时间的标签
    (after! org
      (setq org-log-done t))
    
    ;; Possible values are:
    
    ;;   nil     Don't add anything, just change the keyword
    ;;   time    (or t) Add a time stamp to the task
    ;;   note    Prompt for a note and add it with template org-log-note-headings
    
        
  • [X] 如何设置记录 log 信息到 drawer 中?
    (after! org
      (setq org-log-into-drawer t))
        
  • [X] 如何让任务的 Property 可以被子任务继承
    ;; 比如你想设置 :header-args: :mkdirp yes 之类的属性, 就会希望子任务可
    ;; 以继承
    (after! org
      (setq org-use-property-inheritance t))
        
  • [X] 如何让 C-a 在任务标题上面更好用
    ;; When t, C-a will bring back the cursor to the beginning of the
    ;; headline text, i.e. after the stars and after a possible TODO
    ;; keyword.
    (after! org
      (setq org-special-ctrl-a/e t))
        
  • [X] 如何让 C-k 在任务标题上面更好用
    ;; When t, the following will happen while the cursor is in the
    ;; headline:
    
    ;; - When at the beginning of a headline, kill the entire subtree.
    ;; - When in the middle of the headline text, kill the text up to the
    ;; - tags.
    ;; - When after the headline text and before the tags, kill all
    ;; - the tags.
    (after! org
      (setq org-special-ctrl-k t))
        
  • [X] 如何隐藏任务前面的多个* 符号
    ;; Non-nil means hide the first N-1 stars in a headline.
    (after! org
      (setq org-hide-leading-stars t))
        
  • [X] 如何替换任务折叠状态时尾部的符号
    ;; 替换为你喜欢的符号即可
    (after! org
      (setq org-ellipsis ""))
        
  • [X] 如何插入 heading 的时候, 考虑到当前 subtree 的内容, 在其后插入
    (after! org
      (setq org-insert-heading-respect-content nil))
        
  • [X] 如何在完成任务时, 增加删除划掉样式
    ;; 完成任务时, 将其划线勾掉
    (set-face-attribute 'org-headline-done nil :strike-through t)
    
        

Tag [1/1]

  • [X] 如何设定默认的 Tags
    (after! org
      (setq org-tag-alist '(("@工作" . ?w) ("@生活" . ?l) ("@学习" . ?s))))
        

UI [9/9]

  • [X] 如何自定义各标标题的大小和字体粗细
    (after! org
      (custom-set-faces!
        '(outline-1 :weight extra-bold :height 1.25)
        '(outline-2 :weight bold :height 1.15)
        '(outline-3 :weight bold :height 1.12)
        '(outline-4 :weight semi-bold :height 1.09)
        '(outline-5 :weight semi-bold :height 1.06)
        '(outline-6 :weight semi-bold :height 1.03)
        '(outline-8 :weight semi-bold)
        '(outline-9 :weight semi-bold))
    
      (custom-set-faces!
        '(org-document-title :height 1.2)))
    
        
  • [X] 如何在中英文字符中间自动插入空格
    (use-package! pangu-spacing
      :config
      (global-pangu-spacing-mode 1)
      ;; 在中英文符号之间, 真正地插入空格
      (setq pangu-spacing-real-insert-separtor t))
        
  • [X] 如何美化 bold/code/italitic 等样式
    (use-package! org-appear
      :hook (org-mode . org-appear-mode)
      :config
      (setq org-appear-autoemphasis t
            org-appear-autosubmarkers t
            org-appear-autolinks nil))
    
        
  • [X] 如何更改行间距
    (after! org
      (setq line-spacing 0.25))
        
  • [X] 如何更改加粗样式
    (defface org-bold
      '((t :foreground "#d2268b"
         :background "#fefefe"
         :weight bold
         :underline t
         :overline t))
      "Face for org-mode bold."
      :group 'org-faces )
    
    (setq org-emphasis-alist
          '(("*" org-bold)
            ("/" italic)
            ("_" underline)
            ("=" ;; (:background "maroon" :foreground "white")
             org-verbatim verbatim)
            ("~" ;; (:background "deep sky blue" :foreground "MidnightBlue")
             org-code verbatim)
            ("+" (:strike-through t))))
    
    (set-face-background 'org-bold "#fefefe")
    (set-face-background 'org-verbatim "#fefefe")
        
  • [X] 如何解决中文强调样式前后的空格问题
    ;; https://emacs-china.org/t/org-mode/22313?u=vagrantjoker
    ;; 解决中文标记前后空格的问题
    (require 'ox)
    (font-lock-add-keywords 'org-mode
                            '(("\\cc\\( \\)[/+*_=~][^a-zA-Z0-9]*?[/+*_=~]\\( \\)?\\cc?"
                               (1 (prog1 () (compose-region (match-beginning 1) (match-end 1) ""))))
                              ("\\cc?\\( \\)?[/+*_=~][^a-zA-Z0-9]*?[/+*_=~]\\( \\)\\cc"
                               (2 (prog1 () (compose-region (match-beginning 2) (match-end 2) "")))))
                            'append)
    
    (with-eval-after-load 'org
      (defun eli-strip-ws-maybe (text _backend _info)
        (let* ((text (replace-regexp-in-string
                      "\\(\\cc\\) *\n *\\(\\cc\\)"
                      "\\1\\2" text));; remove whitespace from line break
               ;; remove whitespace from `org-emphasis-alist'
               (text (replace-regexp-in-string "\\(\\cc\\) \\(.*?\\) \\(\\cc\\)"
                                               "\\1\\2\\3" text))
               ;; restore whitespace between English words and Chinese words
               (text (replace-regexp-in-string "\\(\\cc\\)\\(\\(?:<[^>]+>\\)?[a-z0-9A-Z-]+\\(?:<[^>]+>\\)?\\)\\(\\cc\\)"
                                               "\\1 \\2 \\3" text)))
          text))
      (add-to-list 'org-export-filter-paragraph-functions #'eli-strip-ws-maybe))
    
        
  • [X] 如何使用 svg-lib/svg-tag-mode 来美化 UI
    (use-package! svg-tag-mode
      :hook (org-mode . svg-tag-mode)
      :config
      (defun mk/svg-checkbox-empty()
        (let* ((svg (svg-create 14 14)))
          (svg-rectangle svg 0 0 14 14 :fill 'white :rx 2 :stroke-width 2.5 :stroke-color 'black)
          (svg-image svg :ascent 'center)
          ))
    
      (defun mk/svg-checkbox-filled()
        (let* ((svg (svg-create 14 14)))
          (svg-rectangle svg 0 0 14 14 :fill "#FFFFFF" :rx 2)
          (svg-polygon svg '((5.5 . 11) (12 . 3.5) (11 . 2) (5.5 . 9) (1.5 . 5) (1 . 6.5))
                       :stroke-color 'black :stroke-width 1 :fill 'black)
          (svg-image svg :ascent 'center)
          ))
      (defun mk/svg-checkbox-toggle()
        (interactive)
        (save-excursion
          (let* ((start-pos (line-beginning-position))
                 (end-pos (line-end-position))
                 (text (buffer-substring-no-properties start-pos end-pos))
                 (case-fold-search t)  ; Let X and x be the same in search
                 )
            (beginning-of-line)
            (cond ((string-match-p "\\[X\\]" text)
                   (progn
                     (re-search-forward "\\[X\\]" end-pos)
                     (replace-match "[ ]")))
                  ((string-match-p "\\[ \\]" text)
                   (progn
                     (search-forward "[ ]" end-pos)
                     (replace-match "[X]")))
                  ))))
    
      (defun svg-progress-percent (value)
        (svg-image (svg-lib-concat
                    (svg-lib-progress-bar (/ (string-to-number value) 100.0)
                                          nil :margin 0 :stroke 2 :radius 3 :padding 2 :width 11)
                    (svg-lib-tag (concat value "%")
                                 nil :stroke 0 :margin 0)) :ascent 'center))
    
      (defun svg-progress-count (value)
        (let* ((seq (mapcar #'string-to-number (split-string value "/")))
               (count (float (car seq)))
               (total (float (cadr seq))))
          (svg-image (svg-lib-concat
                      (svg-lib-progress-bar (/ count total) nil
                                            :margin 0 :stroke 2 :radius 3 :padding 2 :width 11)
                      (svg-lib-tag value nil
                                   :stroke 0 :margin 0)) :ascent 'center)))
    
      (defconst date-re "[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}")
      (defconst time-re "[0-9]\\{2\\}:[0-9]\\{2\\}")
      (defconst day-re "[A-Za-z]\\{3\\}")
      (defconst day-time-re (format "\\(%s\\)? ?\\(%s\\)?" day-re time-re))
    
      (setq svg-tag-action-at-point 'edit)
    
      (setq svg-lib-icon-collections
            `(("bootstrap" .
               "https://icons.getbootstrap.com/assets/icons/%s.svg")
              ("simple" .
               "https://raw.githubusercontent.com/simple-icons/simple-icons/develop/icons/%s.svg")
              ("material" .
               "https://raw.githubusercontent.com/Templarian/MaterialDesign/master/svg/%s.svg")
              ("octicons" .
               "https://raw.githubusercontent.com/primer/octicons/master/icons/%s-24.svg")
              ("boxicons" .
               "https://boxicons.com/static/img/svg/regular/bx-%s.svg")))
    
      (setq svg-tag-tags
            `(
              ;; Task priority
              ("\\[#[A-Z]\\]" . ( (lambda (tag)
                                    (svg-tag-make tag :face 'org-priority
                                                  :beg 2 :end -1 :margin 0))))
    
              ;; Progress
              ("\\(\\[[0-9]\\{1,3\\}%\\]\\)" . ((lambda (tag)
                                                  (svg-progress-percent (substring tag 1 -2)))))
              ("\\(\\[[0-9]+/[0-9]+\\]\\)" . ((lambda (tag)
                                                (svg-progress-count (substring tag 1 -1)))))
    
              ;; Checkbox
              ("\\[ \\]" . ((lambda (_tag) (mk/svg-checkbox-empty))
                            (lambda () (interactive) (mk/svg-checkbox-toggle))
                            "Click to toggle."
                            ))
              ("\\(\\[[Xx]\\]\\)" . ((lambda (_tag) (mk/svg-checkbox-filled))
                                     (lambda () (interactive) (mk/svg-checkbox-toggle))
                                     "Click to toggle."))
    
              ;; Active date (with or without day name, with or without time)
              (,(format "\\(<%s>\\)" date-re) .
               ((lambda (tag)
                  (svg-tag-make tag :beg 1 :end -1 :margin 0))))
              (,(format "\\(<%s \\)%s>" date-re day-time-re) .
               ((lambda (tag)
                  (svg-tag-make tag :beg 1 :inverse nil :crop-right t :margin 0))))
              (,(format "<%s \\(%s>\\)" date-re day-time-re) .
               ((lambda (tag)
                  (svg-tag-make tag :end -1 :inverse t :crop-left t :margin 0))))
    
              ;; Inactive date  (with or without day name, with or without time)
              (,(format "\\(\\[%s\\]\\)" date-re) .
               ((lambda (tag)
                  (svg-tag-make tag :beg 1 :end -1 :margin 0 :face 'org-date))))
              (,(format "\\(\\[%s \\)%s\\]" date-re day-time-re) .
               ((lambda (tag)
                  (svg-tag-make tag :beg 1 :inverse nil :crop-right t :margin 0 :face 'org-date))))
              (,(format "\\[%s \\(%s\\]\\)" date-re day-time-re) .
               ((lambda (tag)
                  (svg-tag-make tag :end -1 :inverse t :crop-left t :margin 0 :face 'org-date))))
    
              ;; Keywords
              ("TODO" . ((lambda (tag) (svg-tag-make tag :height 0.8 :inverse t
                                                     :face 'org-todo :margin 0 :radius 5))))
              ("WORK" . ((lambda (tag) (svg-tag-make tag :height 0.8
                                                     :face 'org-todo :margin 0 :radius 5))))
              ("DONE" . ((lambda (tag) (svg-tag-make tag :height 0.8 :inverse t
                                                     :face 'org-done :margin 0 :radius 5))))
    
              ("FIXME\\b" . ((lambda (tag) (svg-tag-make "FIXME" :face 'org-todo :inverse t :margin 0 :crop-right t))))
    
              ;; beautify pagebreak in orgmode
              ("\\\\pagebreak" . ((lambda (tag) (svg-lib-icon "file-break" nil :collection "bootstrap"
                                                              :stroke 0 :scale 1 :padding 0))))
    
              )))
        
  • [X] 如何改变符号展示
    (font-lock-add-keywords
     'org-mode
     '(("^ +\\([-*]\\) "
        (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) ""))))))
        
  • [X] 如何改变任意字符串为 Unicode 符号
    (defun my-add-pretty-symbol ()
      "make some word display as Unicode symbols"
      (setq prettify-symbols-alist
            '(
              ("\\pagebreak" . 128204)
              ("->" . 8594)    ;
              ("=>" . 8658)    ;
              )))
    
    (add-hook 'org-mode-hook 'my-add-pretty-symbol)
        

About

It's all about *orgmode* !

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published