emacs simpc-mode provided by tsoding -- sure on windows

# 事实上我不是很懂emacs的配置,这个simpc-mode也只是简单的不得了,没有类ide的体验

# init.el -- file@appdata\romaing\.emacs.d\init.el

;; pre init elisp conf
(menu-bar-mode 1)                                               ;; 隐藏菜单栏
(blink-cursor-mode 1)                                            ;; 开启光标闪烁
(tool-bar-mode -1)                                               ;; 隐藏工具栏
(scroll-bar-mode -1)                                             ;; 滚动栏隐藏                                           
(show-paren-mode t)                                              ;; 括号配对
(electric-pair-mode t)                                           ;; 自动补全括号
(global-hl-line-mode -1)                                          ;; 高亮当前行
(global-auto-revert-mode 1)                                      ;; 自动加载外部修改过的文件
(delete-selection-mode 1)                                        ;; 当你选中一段文字 之后输入一个字符会替换掉你选中部分的文字。
(fset 'yes-or-no-p 'y-or-n-p)                                    ;; 简化yes no
(setq-default cursor-type 'bar)                                  ;; 设置光标为线状
(setq                                    
      frame-title-mode t                                         ;; 在窗口的标题栏上显示文件名称
      frame-title-format "filename: %b"                              ;; 设置标题栏
      inhibit-splash-screen t                                    ;; 关闭启动画面
      gnus-inhibit-startup-message t                             ;; 关闭引导界面
      make-backup-files nil                                      ;; 关闭自动备份文件~
      backup-inhibited t                                         ;; 不产生备份
      auto-save-mode nil                                         ;; 自动保存模式
      truncate-lines nil                                         ;; 自动换行
      transient-mark-mode t                                      ;; 高亮显示选择区域
      global-font-lock-mode t                                    ;; 进行语法加亮
      show-paren-style 'parenthesis                              ;; 只高亮括号
      require-final-newline t                                    ;; 自动的在文件末增加一新行
      track-eol t                                                ;; 当光标在行尾上下移动的时候,始终保持在行尾。
      c-default-style "awk"                                      ;; 设置c++编译颜色风格
      initial-frame-alist (quote ((fullscreen . maximized)))     ;; 默认全屏
)
(load-theme 'tango-dark)
(global-display-line-numbers-mode 1)

;; auto save code conf
(defgroup auto-save nil
  "Auto save file when emacs idle."
  :group 'auto-save)

(defcustom auto-save-idle 0.1;;!!!!!!!!!!!!
  "The idle seconds to auto save file."
  :type 'integer
  :group 'auto-save)

(defcustom auto-save-slient nil
  "Nothing to dirty minibuffer if this option is non-nil."
  :type 'boolean
  :group 'auto-save)

(setq auto-save-default nil)

;; 前方高能核心代码, 请集中注意力
(defun auto-save-buffers ()
  (interactive)
  (let ((autosave-buffer-list))
    (save-excursion
      (dolist (buf (buffer-list))
        (set-buffer buf)
        (if (and (buffer-file-name) (buffer-modified-p))
            (progn              
              (push (buffer-name) autosave-buffer-list)
              (if auto-save-slient                  
                  (with-temp-message ""
                    (basic-save-buffer))
                (basic-save-buffer))
              )))
      (unless auto-save-slient
        (cond
         ((= (length autosave-buffer-list) 1)
          (message "# Saved %s" (car autosave-buffer-list)))
         ((> (length autosave-buffer-list) 1)
          (message "# Saved %d files: %s"
                   (length autosave-buffer-list)
                   (mapconcat 'identity autosave-buffer-list ", "))))))))

(defun auto-save-enable ()
  (interactive)
  (run-with-idle-timer auto-save-idle t #'auto-save-buffers))
(auto-save-enable);; 开启自动保存功能
(setq auto-save-slient t);; 自动保存的时候静悄悄的, 不要打扰我


;;; 别人的插件所有配置代码
(defvar plugin-home-dir "C:/Users/etcix/AppData/Roaming/.emacs.d/packages/")
;tsoding的c-mode,我不确定能不能使用 M-x simpc-mode 
(add-to-list 'load-path (concat plugin-home-dir "simpc-mode"))
(require 'simpc-mode)

# packages\simpc-mode\simpc-mode.el

(require 'subr-x)

(defvar simpc-mode-syntax-table
  (let ((table (make-syntax-table)))
    ;; C/C++ style comments
	(modify-syntax-entry ?/ ". 124b" table)
	(modify-syntax-entry ?* ". 23" table)
	(modify-syntax-entry ?\n "> b" table)
    ;; Preprocessor stuff?
    (modify-syntax-entry ?# "." table)
    ;; Chars are the same as strings
    (modify-syntax-entry ?' "\"" table)
    ;; Treat <> as punctuation (needed to highlight C++ keywords
    ;; properly in template syntax)
    (modify-syntax-entry ?< "." table)
    (modify-syntax-entry ?> "." table)

    (modify-syntax-entry ?& "." table)
    (modify-syntax-entry ?% "." table)
    table))

(defun simpc-types ()
  '("char" "int" "long" "short" "void" "bool" "float" "double" "signed" "unsigned"
    "char16_t" "char32_t" "char8_t"
    "int8_t" "uint8_t" "int16_t" "uint16_t" "int32_t" "uint32_t" "int64_t" "uint64_t"
    "uintptr_t"
    "size_t"))

(defun simpc-keywords ()
  '("auto" "break" "case" "const" "continue" "default" "do"
    "else" "enum" "extern" "for" "goto" "if" "register"
    "return"  "sizeof" "static" "struct" "switch" "typedef"
    "union"  "volatile" "while" "alignas" "alignof" "and"
    "and_eq" "asm" "atomic_cancel" "atomic_commit" "atomic_noexcept" "bitand"
    "bitor" "catch"  "class" "co_await"
    "co_return" "co_yield" "compl" "concept" "const_cast" "consteval" "constexpr"
    "constinit" "decltype" "delete" "dynamic_cast" "explicit" "export" "false" 
    "friend" "inline" "mutable" "namespace" "new" "noexcept" "not" "not_eq"
    "nullptr" "operator" "or" "or_eq" "private" "protected" "public" "reflexpr"
    "reinterpret_cast" "requires" "static_assert" "static_cast" "synchronized"
    "template" "this" "thread_local" "throw" "true" "try" "typeid" "typename"
    "using" "virtual" "wchar_t" "xor" "xor_eq"))

(defun simpc-font-lock-keywords ()
  (list
   `("# *[#a-zA-Z0-9_]+" . font-lock-preprocessor-face)
   `("#.*include \\(\\(<\\|\"\\).*\\(>\\|\"\\)\\)" . (1 font-lock-string-face))
   `(,(regexp-opt (simpc-keywords) 'symbols) . font-lock-keyword-face)
   `(,(regexp-opt (simpc-types) 'symbols) . font-lock-type-face)))

;;; TODO: try to replace simpc--space-prefix-len with current-indentation
(defun simpc--space-prefix-len (line)
  (- (length line)
     (length (string-trim-left line))))

(defun simpc--previous-non-empty-line ()
  (save-excursion
    (forward-line -1)
    (while (and (not (bobp))
                (string-empty-p
                 (string-trim-right
                  (thing-at-point 'line t))))
      (forward-line -1))
    (thing-at-point 'line t)))

(defun simpc--desired-indentation ()
  (let ((cur-line (string-trim-right (thing-at-point 'line t)))
        (prev-line (string-trim-right (simpc--previous-non-empty-line)))
        (indent-len 4))
    (cond
     ((and (string-suffix-p "{" prev-line)
           (string-prefix-p "}" (string-trim-left cur-line)))
      (simpc--space-prefix-len prev-line))
     ((string-suffix-p "{" prev-line)
      (+ (simpc--space-prefix-len prev-line) indent-len))
     ((string-prefix-p "}" (string-trim-left cur-line))
      (max (- (simpc--space-prefix-len prev-line) indent-len) 0))
     (t (simpc--space-prefix-len prev-line)))))

;;; TODO: customizable indentation (amount of spaces, tabs, etc)
(defun simpc-indent-line ()
  (interactive)
  (when (not (bobp))
    (let* ((current-indentation
            (simpc--space-prefix-len (thing-at-point 'line t)))
           (desired-indentation
            (simpc--desired-indentation))
           (n (max (- (current-column) current-indentation) 0)))
      (indent-line-to desired-indentation)
      (forward-char n))))

(define-derived-mode simpc-mode prog-mode "Simple C"
  "Simple major mode for editing C files."
  :syntax-table simpc-mode-syntax-table
  (setq-local font-lock-defaults '(simpc-font-lock-keywords))
  (setq-local indent-line-function 'simpc-indent-line)
  (setq-local comment-start "// "))

(provide 'simpc-mode)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值