Skip to content

rexim/simpc-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

Simple C mode for Emacs

Because whatever comes with Emacs is too slow.

This mode does not try to be as featureful as c-mode, c++-mode, cc-mode, etc. Instead we are trying to implement a bare minimum syntax highlighting and indentation to maintain high performance on big files with long lines.

The goal is to be able to comfortably browse and modify the following files:

Right now the only way to work with these files in Emacs is to use text-mode. Which is actually a good evidence that Emacs itself can handle such files! It's c-mode (and others) that cannot.

Installing locally

Put simpc-mode.el to some folder /path/to/simpc/. Add this to your .emacs:

;; Adding `/path/to/simpc` to load-path so `require` can find it
(add-to-list 'load-path "/path/to/simpc/")
;; Importing simpc-mode
(require 'simpc-mode)
;; Automatically enabling simpc-mode on files with extensions like .h, .c, .cpp, .hpp
(add-to-list 'auto-mode-alist '("\\.[hc]\\(pp\\)?\\'" . simpc-mode))

Indentation

Right now the mode supports only very simple indentations based on the analysing the previous non-empty line and its surrounding curly braces. Anything more complicated is outside of the scope of the project.

It is recommended to use an external formatter such as indent, astyle, clang-format, etc.

Here is how I use astyle:

(defun astyle-buffer ()
  (interactive)
  (let ((saved-line-number (line-number-at-pos)))
    (shell-command-on-region
     (point-min)
     (point-max)
     "astyle --style=kr"
     nil
     t)
    (goto-line saved-line-number)))

Then I bind astyle-buffer to some key combination and invoke it periodically to reformat the whole current buffer.

About

Simple C mode for Emacs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •