Emacs 启动期间如何运行自定义代码
在 Emacs 启动期间运行自定义代码可以通过创建一个启动文件并设置合适的参数来实现。以下是创建自定义启动文件的基本步骤:
my-emacs-startup.el
的文件。my-emacs-startup.el
文件,并添加以下代码:;; 引入 Emacs Lisp 库
(setq elisp-package-dir (concat emacs-lisp-package-dir "/"))
;; 设置自定义启动文件路径
(setq custom-file (concat user-emacs-directory "custom.el"))
;; 判断是否存在自定义启动文件,并加载
(if (file-exists-p custom-file)
(load custom-file)
(progn
(message "No custom file found.")
(sit-for 1))
)
;; 定义一个函数来运行自定义代码
(defun run-my-code ()
(interactive)
(let ((my-code (concat ";; " (buffer-name) " --- My Code Executed")))
(insert my-code)
(save-buffer)
(kill-buffer))))
;; 设置自定义启动命令
(setq custom-startup-command '("my-emacs-startup" . (lambda () (interactive) (run-my-code))))
*scratch*
缓冲区,并输入 (load-file "my-emacs-startup.el")
。.emacs
文件中,添加以下代码:
(setq auto-mode-alist
(cons '("\\.py\\'" . python-mode)
auto-mode-alist))
(global-set-key (kbd "C-c C-c") 'compile)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-c C-k") 'kill-compilation)
(global-set-key (kbd "C-c C-t") 'recompile)
(global-set-key (kbd "C-c C-w") 'kill-some-buffers)
(global-set-key (kbd "C-c C-l") 'load-file)
(global-set-key (kbd "C-c C-i") 'find-function)
(global-set-key (kbd "C-c C-t") 'find-tag)
(global-set-key (kbd "C-c C-d") 'find-definition)
(global-set-key (kbd "C-c C-f") 'find-function-on-key)
(global-set-key (kbd "C-c C-s") 'comment-or-uncomment-region)
(global-set-key (kbd "C-c C-k") 'kill-line)
(global-set-key (kbd "C-c C-j") 'join-line)
(global-set-key (kbd "C-c C-q") 'quote-insert)
(global-set-key (kbd "C-c C-x") 'exchange-point-and-mark)
(global-set-key (kbd "C-c C-z") 'undo)
(global-set-key (kbd "C-c C-a") 'beginning-of-line)
(global-set-key (kbd "C-c C-e") 'end-of-line)
(global-set-key (kbd "C-c C-w") 'kill-region)
(global-set-key (kbd "C-c C-x") 'kill-paragraph)
(global-set-key (kbd "C-c C-l") 'insert-file)
(global-set-key (kbd "C-c C-i") 'insert-image)
(global-set-key (kbd "C-c C-t") 'insert-table)
(global-set-key (kbd "C-c C-d") 'insert-directory)
(global-set-key (kbd "C-c C-f") 'find-function)
(global-set-key (kbd "C-c C-
高校公开课
Tencent Serverless Hours 第13期
Techo Day
技术创作101训练营
北极星训练营
技术创作101训练营
Lowcode Talk
双11音视频系列直播
云原生正发声
Elastic 实战工作坊
领取专属 10元无门槛券
手把手带您无忧上云