nowislewis / nowisemacs

A full-blown emacs configuration framework with easy abstraction
47 stars 8 forks source link

+begin_src elisp


|\ \ \ \ _ _ / /| |\ \ / \ \ \ \ \ | | / / \ / / | | \ \ |_/\ \_/| / / \ | \ \ | | / /\ || / || \ | |____\ \|/ | | //| | \ | | | | | || | | | | | | | __\ \ | || | | | | | | || \ \ / / | / / __ / /\ ||/ / /\ \ | | / /|| |\/ \//| | / \/ // || |/ \ \ /____/ /__/||\ _/ ||_|_/|//||____/||__\ /__/| | | | | || \\ | / | | | | | | | || | /| | || | | |__|/|__|/ \ | ||/ |__|||/|_|/ |___|/ |_||__|/ |____|

+end_src

It's designed by following principles:

Nowisemacs uses a single org file to manage all configurations. To reduce the startup time of emacs, users need to generate =.el= configuration files before the first startup

* Installation ** Dependences

  1. Install =ripgrep= and =fd=. **** Nowisemacs
  2. =mv ~/.emacs.d ~/.emacs.d.back= ;; Backup your original configuration
  3. =git clone https://github.com/nowislewis/nowisemacs ~/.emacs.d= ;; Download nowisemacs
  4. =cd ~/.emacs.d=
  5. =make bootstrap-borg & make bootstrap= ;; download and build packages
  6. (optional) =make native= ;; if you build emacs with native-comp, use this command to build all packages ahead-of-time.
  7. =emacs= ;; Launch emacs, the download, installation and configuration of packages will be done automatically.
  8. M-x
  9. If you upgrade packages or install new packages, just run =make= in the =.emacs.d= dir. *** Add packages
  10. Inside emacs, run =M-x borg-assimilate=, and then input your package name and git url sequentially.
  11. Run =M-x borg-active=, choose the package you just installed. *** Remove packages
  12. Inside emacs, run =M-x borg-remove=, choose the package you want to remove. *** Update packages
  13. =make update= ;; get all packages update latest
  14. =git add .=, then =make build= ;; build packages
  15. (optional) =make native= ;; if you build emacs with native-comp, use this command to build all packages ahead-of-time. * display icons correctly nerd-icons are necessary. Run M-x nerd-icons-install-fonts to install the resource fonts. On Windows, the fonts should be installed manually. nerd-icons supports bot GUI and TUI. * How to customize Change configurations Nowisemacs use =setup.el= to config all the configuration but you can also use built-in methods, =setup= is just a simple wrapper of these methods. You can get a clear understand in anywhere by typing =M-x emacs-lisp-macroexpand=, and the =setup= code will be expanded to normal built-in methods.

Every time you make some changes on =~/.emacs.d/init.org= (eg, write down =<s= and then use =tab= to get a expanded src code), you should run =make init-build=. You can also just use =make= to config everything. This will overwrite =~/.emacs.d/init.el= and =early-init.el=. Nowisemacs use this method to guarantee the =init.el= will not be changed by mistake =custom-group= or something else. *** Everyday use(a summary) That't to say, after installation, there are only things you need to remember for everyday use:

  1. =borg-assimilate= for install packages, and =borg-remove= for remove packages.
  2. =make update= for updates. After update, run =git add .= to add all updates, and =make build= to get them compiled.
  3. =make init-build= if you only changed the =init.org= file.
  4. If you modify a local package under lib such as =foo=, run =make lib/foo= to recompile only that package.

It's suggested to read the [[https://emacsmirror.net/manual/borg/][borg]] for more details. *** Some explanation about package configurations/setup.el

I use XiaoHeShuangPin for Pinyin search, it will affect all searching jobs with vertico ** vim users should care Some useful keybindings for vim user: | Button | Function | |----------------+--------------------------------------------------------------------------------| | C-a | Go to the beginning of the current visible line | | C-e | Go to the end of the line, but before ellipsis, if any | | M-> | Move point to the end of the buffer | | M-< | Move point to the beginning of the buffer | | M-v | Scroll text of selected window down ARG lines; or near full screen if no ARG | | C-v | Scroll text of selected window upward ARG lines; or near full screen if no ARG | | C-w | Kill ("cut") text between point and mark | | e | meow-next-word, select to the end of the next Nth word | | b | meow-back-word, select to the beginning the previous Nth word | | f | meow-find, find the next N char read from minibuffer | | c c | meow-change, kill current selection and switch to INSERT state | | n | moew-search, search and select with the car of the current regexp-search-ring | | v a | text-object based operation (arounding objects) | | v i | text-object based operation (inside objects) | | m + any letter | save the current location into registers with name "letter" | | ' + any letter | load the location registers of name "letter" | | g d | jump to definition | | g D | jump to reference | | g a | code actions |

Press =Space ?= to get a view of keybings under normal status.

After heavy use for a period of time, I gave up use-package and leaf. They have a high degree of abstraction and thus complex mechanisms, which is not conducive to understanding and debugging.

At the suggestion of Lazycat, a great Emacs contributor, I have used the native way to configure Emacs for a while. I really like this idea, it is clear and easy to drill down. No black box here.

But if you use the native way, you will find that there is a lot of duplicated codes, which make the work tedious and increase the maintenance work. =setup= comes into view. First, =setup= is almost indistinguishable from the native way at the level of abstraction. =setup= is actually a bunch of simple macros to generate code. And the code generated after macro-expand is almost the same as native methods. So =setup= is also clear and easy to drill down as native way.

The function of =setup= is to turn these repeated codes into simple calls, which are equivalent to defining one place, but can be used everywhere.

What's more, =setup= can easily change the code context such as keymap context or hook context. It's easy to get complex configuration clear. ** How to become a proficient user in emacs I would like to first give my own experience through these difficulties for beginners:

  1. I have been using doom emacs for a long time, which is a great configuration framework for vim users. During that, I was mainly familiar with various cool or practical functions of emacs, which greatly aroused interest and made it clear what an excellent emacs should be and what does it look like.
  2. Then I found I need some personal features for my daily work, but it's hard to achieve an end because it's always easy to get stuck in a lot of code traps. I don't know how to sort out my own process.
  3. After some time I found a very native configuration, lazycat-emacs, and learned how to configure all the code in the lowest-level way, including manually managing packages, manually controlling the loading order, etc.
  4. After understanding what I need to set after startup. Things I needed to figure out became clear again:
    • First, to implement whatever features I need.
    • Second, to control the abstraction level of the configuration so as not to increase maintenance pressure.

The configuration of nowisemacs is not there all at once. There is an article "Understanding emacs from the perspective of operating system architecture" that gave me a good inspiration, let me try to use emacs from the perspective of an emacs itself rather than an emacs user. As an emacs, how can I meet user needs?

With this idea in mind, nowisemacs tries to separate functional structure and code structure to solve this problem.