~cytrogen/.emacs.d

ref: 504e0080a3f94c9824ac305b1a24b30c7d1fb051 .emacs.d/config/utils.el -rw-r--r-- 3.7 KiB
504e0080 — HallowDem feat: 添加博客图片插入功能 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
;;; utils.el --- Utility functions and dashboard -*- lexical-binding: t -*-

;; Copyright (C) 2024 Cytrogen

;; This file contains:
;; - Custom dashboard and startup screen
;; - File and system utilities
;; - Diagnostic and troubleshooting functions
;; - General helper functions

;;; Commentary:

;; Collection of utility functions and the custom dashboard that provides
;; a GTD-focused startup experience.

;;; Code:

;; File Utilities
;; File operation helper functions
(defun my/open-init-file ()
  "Open the Emacs init.el file."
  (interactive)
  (find-file user-init-file))

(defun my/reload-init-file ()
  "Reload the Emacs init.el file."
  (interactive)
  (load-file user-init-file)
  (message "Init file reloaded."))

;; Custom Dashboard
;; GTD-focused startup screen
(defun my/show-dashboard ()
  "Render a custom GTD dashboard."
  (interactive)
  (let ((buf (get-buffer-create "*Cytrogen's Home*")))
    (with-current-buffer buf
      (let ((inhibit-read-only t))
        (erase-buffer)

	      ;; Header
        (insert "#+TITLE: Cytrogen 的个人领地\n")
        (insert "#+STARTUP: showall\n\n")

        (insert "\n")
        (insert "Welcome back, Cytrogen.\n")
        (insert "------------------------------------\n\n")
            
        ;; GTD Intro
        (insert "* GTD 工作流指南\n\n")
        (insert "1. Capture(收集): 大脑用来思考,不是用来记事的。\n")
        (insert "   任何想法、任务、灵感,第一时间通过 Capture 放入 Inbox。\n")
        (insert "   - [C-c c] 唤起 Capture 面板\n")
        (insert "   - [C-c C-c] 确认保存\n")
        (insert "   - [C-c C-k] Abort (放弃/取消)\n\n")
        
        (insert "2. Process(整理): 清空 Inbox。\n")
        (insert "   每天/每周定期检查 Inbox,将任务移动到具体的项目或归档。\n")
        (insert "   - [C-c w] Quick Refile (快速移动条目)\n\n")
        
        (insert "3. Do(执行): 专注当下。\n")
        (insert "   通过 Agenda 查看今日待办。\n")
        (insert "   - [C-c a] 打开 Agenda 视图\n\n")

        ;; Keybindings Cheatsheet
        (insert "* 常用命令\n\n")
        (insert "| 快捷键 | 描述 | 命令 |\n")
        (insert "|---|---|---|\n")
        (insert "| C-c c | 快速记录 | org-capture |\n")
        (insert "| C-c a | 日程/代办 | org-agenda |\n")
        (insert "| C-c w | 快速归档 | my/quick-refile |\n")
        (insert "| C-c o | 打开笔记 | my/open-org-file |\n")
        (insert "| C-c m | 长毛象 | mastodon |\n")
        (insert "| C-c i | 编辑配置 | my/open-init-file |\n")
        (insert "| C-c r | 重载配置 | my/reload-init-file |\n")
        
        ;; Footer
        (insert "\n「保持简单,保持流动。」\n")

        (org-mode)
        (when (fboundp 'my/org-mode-visual-setup)
          (my/org-mode-visual-setup))
        (org-indent-mode 1)
        (visual-line-mode 1)

        ;; 跳过被隐藏的元数据行,将视图定位到第一行可见文本
        (while (get-char-property (point) 'invisible)
          (forward-line 1))))

    (switch-to-buffer buf)
    
    ;; 延迟定位到第一行可见内容
    (run-with-idle-timer 0.1 nil 
      (lambda ()
        (when (and (get-buffer "*Cytrogen's Home*")
                   (string= (buffer-name (current-buffer)) "*Cytrogen's Home*"))
          (goto-char (point-min))
          (while (and (not (eobp)) 
                      (get-char-property (point) 'invisible))
            (forward-line 1)))))))

;; Dashboard startup configuration
(setq inhibit-startup-screen t)
(add-hook 'emacs-startup-hook #'my/show-dashboard)

;; System Diagnostics
;; Troubleshooting and status functions

;; General Utilities
;; Miscellaneous helper functions

(provide 'utils)
;;; utils.el ends here