Config: streamline config structure and reorganize modules
- Remove init-workspace.el and redundant UI/font/autothemer setup - Add init-prog.el for programming language configs (treesit, lua, scheme, etc.) - Defer org-refile loading via org-mode hook - Adjust load order in init.el, add init-proxy - Fix indentation and formatting issues
This commit is contained in:
@@ -21,40 +21,7 @@
|
||||
(add-hook 'gptel-post-response-functions 'gptel-end-of-response)
|
||||
(add-hook 'gptel-post-stream-hook 'gptel-auto-scroll)
|
||||
|
||||
(setq gptel-prompt-prefix-alist '((markdown-mode . "### ") (org-mode . "** User: ") (text-mode . "### ")))
|
||||
|
||||
;; 读取文件
|
||||
(gptel-make-tool
|
||||
:function (lambda (filepath)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (expand-file-name filepath))
|
||||
(buffer-string)))
|
||||
:name "read_file"
|
||||
:description "Read and display the contents of a file"
|
||||
:args '((:name "filepath" :type string :description "Path to the file"))
|
||||
:category "filesystem")
|
||||
|
||||
;; 创建文件
|
||||
(gptel-make-tool
|
||||
:name "create_file" ; javascript-style snake_case name
|
||||
:function (lambda (path filename content) ; the function that runs
|
||||
(let ((full-path (expand-file-name filename path)))
|
||||
(with-temp-buffer
|
||||
(insert content)
|
||||
(write-file full-path))
|
||||
(format "Created file %s in %s" filename path)))
|
||||
:description "Create a new file with the specified content"
|
||||
:args (list '(:name "path" ; a list of argument specifications
|
||||
:type string
|
||||
:description "The directory where to create the file")
|
||||
'(:name "filename"
|
||||
:type string
|
||||
:description "The name of the file to create")
|
||||
'(:name "content"
|
||||
:type string
|
||||
:description "The content to write to the file"))
|
||||
:category "filesystem") ; An arbitrary label for grouping
|
||||
|
||||
(setq gptel-prompt-prefix-alist '((markdown-mode . "## User: ") (org-mode . "** User: ") (text-mode . "## User: ")))
|
||||
|
||||
(gptel-make-tool
|
||||
:name "read_buffer" ; javascript-style snake_case name
|
||||
@@ -110,41 +77,41 @@ from the last 1500 characters of the buffer."
|
||||
tail)))
|
||||
(message "Generating filename with AI...")
|
||||
(let ((fsm (gptel-request prompt-text
|
||||
:system "You are a filename generator. Output ONLY a short kebab-case filename (3-5 lowercase English words separated by hyphens). No explanations, no quotes, no punctuation, no file extension."
|
||||
:stream nil
|
||||
:callback
|
||||
(lambda (response info)
|
||||
(condition-case err
|
||||
(cond
|
||||
((null response)
|
||||
(message "Failed to generate filename: %s"
|
||||
(or (plist-get info :status) "unknown error")))
|
||||
((not (stringp response))
|
||||
(message "Unexpected response type: %S" response))
|
||||
(t
|
||||
(let* ((generated (my-gptel--sanitize-filename (string-trim response)))
|
||||
(generated (if (string-empty-p generated)
|
||||
"gptel-session"
|
||||
generated))
|
||||
(timestamp (format-time-string "%Y%m%d-%H%M%S"))
|
||||
(dir (expand-file-name "~/gptel/"))
|
||||
(base (concat timestamp "-" generated))
|
||||
(file (expand-file-name (concat base ".org") dir)))
|
||||
;; handle name collision
|
||||
(when (file-exists-p file)
|
||||
(setq base (concat timestamp "-" generated "-" (format-time-string "%S")))
|
||||
(setq file (expand-file-name (concat base ".org") dir)))
|
||||
(unless (file-directory-p dir)
|
||||
(make-directory dir t))
|
||||
;; write-file triggers gptel--save-state to preserve metadata
|
||||
(with-current-buffer buf
|
||||
(write-file file))
|
||||
(if (file-exists-p file)
|
||||
(progn
|
||||
(pop-to-buffer (find-file-noselect file))
|
||||
(message "Saved gptel session to %s" file))
|
||||
(message "ERROR: File was not created: %s" file)))))
|
||||
(error (message "gptel save-session error: %S" err)))))))
|
||||
:system "You are a filename generator. Output ONLY a short kebab-case filename (3-5 lowercase English words separated by hyphens). No explanations, no quotes, no punctuation, no file extension."
|
||||
:stream nil
|
||||
:callback
|
||||
(lambda (response info)
|
||||
(condition-case err
|
||||
(cond
|
||||
((null response)
|
||||
(message "Failed to generate filename: %s"
|
||||
(or (plist-get info :status) "unknown error")))
|
||||
((not (stringp response))
|
||||
(message "Unexpected response type: %S" response))
|
||||
(t
|
||||
(let* ((generated (my-gptel--sanitize-filename (string-trim response)))
|
||||
(generated (if (string-empty-p generated)
|
||||
"gptel-session"
|
||||
generated))
|
||||
(timestamp (format-time-string "%Y%m%d-%H%M%S"))
|
||||
(dir (expand-file-name "~/gptel/"))
|
||||
(base (concat timestamp "-" generated))
|
||||
(file (expand-file-name (concat base ".org") dir)))
|
||||
;; handle name collision
|
||||
(when (file-exists-p file)
|
||||
(setq base (concat timestamp "-" generated "-" (format-time-string "%S")))
|
||||
(setq file (expand-file-name (concat base ".org") dir)))
|
||||
(unless (file-directory-p dir)
|
||||
(make-directory dir t))
|
||||
;; write-file triggers gptel--save-state to preserve metadata
|
||||
(with-current-buffer buf
|
||||
(write-file file))
|
||||
(if (file-exists-p file)
|
||||
(progn
|
||||
(pop-to-buffer (find-file-noselect file))
|
||||
(message "Saved gptel session to %s" file))
|
||||
(message "ERROR: File was not created: %s" file)))))
|
||||
(error (message "gptel save-session error: %S" err)))))))
|
||||
(unless (plist-get (gptel-fsm-info fsm) :callback)
|
||||
(message "WARNING: gptel-request did not register callback!")))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user