加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.org 13.93 KB
一键复制 编辑 原始数据 按行查看 历史
SpringHan 提交于 2023-10-14 16:40 . Refactored sniem.el

Sniem

中文文档

Screenshot

screenshot.png

Dependences

  • s
  • dash

Installation

(use-package
 sniem
 :init (global-sniem-mode t)
 :config
 (sniem-set-keyboard-layout 'qwerty))

What is sniem

Sniem means Hands-eased United Editing Method,it’s a new editing method for Emacs.

Features

  • last-point

    last-point is a thing that through all motions and most of operations. Like its name, when execute any motions, the last position will be set to last-point.

  • leader-key

    Sniem has leader key,the key of leader map can be set by (sniem-leader-set-key). And you can use (sniem-set-leader-key) to set the key of leader.

    (sniem-leader-set-key
     "d" 'sniem-digit-argument-or-fn
     "D" 'dired)
    (sniem-set-leader-key ",")
        
  • Modes

    Sniem has 5 modes.

    • NORMAL: This mode is the default mode for the editing buffers.

      You can use (sniem-normal-set-key) to set keys for normal mode. Its usage is same as (sniem-leader-set-key).

    • INSERT: This mode will be used when you executed sniem-insert in NORMAL mode. It’s used to edit. In this mode, there’s only one binding for sniem, that is <ESC> which will make you exit INSERT mode back to NORMAL mode.
    • MOTION: This mode is used in special modes, there’s only has one binding for sniem, that is <SPC> which can let you use leader keys.
    • EXPAND: This mode is used to expand region more comfortablely.

      You can use (sniem-expand-set-key) to set keys for normal mode. Its usage is same as (sniem-leader-set-key).

      Key Function
      RET Call the object-catch function
      TAB sniem-shift
      r Repeat the object-catch
      p Catch the parent pair of the content selected
      b Catch pair by its prefix char
      B Catch the parent pair of the content selected by its prefix char
      o Catch () pair
      O Catch parent () pair for the content selected
      s Catch [] pair
      S Catch parent [] pair for the content selected
      c Catch {} pair
      C Catch parent {} pair for the content selected
      q Catch ~”~ pair
      Q Catch parent ~”~ pair for the content selected
      d Catch ~”“~ pair
      D Catch parent ~”“~ pair for the content selected
      a Catch <> pair
      A Catch parent <> pair for the content selected
      / Reverse the direction of catch
      Other alpha keys Quit expand mode and goto NORMAL mode
    • MINIBUFFER-KEYPAD: This mode allows you to use keypad in any minibuffers.

      When you’re in a minibuffer, you can input as usual. But when you input space in twice time, the keypad mode will be opened. And you can input space twice to exit keypad mode.

    • Keyboard layout

      Sniem provides supports for the mainly 4 layouts,you can use (sniem-set-keyboard-layout) to set.

      (sniem-set-keyboard-layout 'qwerty)
      (sniem-set-keyboard-layout 'colemak)
      (sniem-set-keyboard-layout 'dvorak)
      (sniem-set-keyboard-layout 'dvp)        ;For Dvorak Programmer
              

      After you set the keyboard layout, Sniem will set the default keys in NORMAL mode accroding to your layout, then create the cheatsheet.

    • Keypad

      Sniem provides the Keypad function, After you execute the Keypad, When you press: , is C- , . is M- , / is C-M- . After you press <SPC>, it will reture the next key itself which you press.

    • middle-keyboard-digit-argument-or-function

      This function is defaultly bound on <SPC>. After you execute it, the middle keys of the keyboard can be instead of numbers and -, the record will be over after you pressed <SPC>. You can also use the keys in the table to do the special operations:

      Key Function
      , Repeat object-catch
      . Mark the content at point or a region
      k Unmark the content and select it
      K Pop the newest marked-content
      SPC Execute function in motion-hint
      / Reverse the direction of object-catch
      p Add, change or delete the pair of region
      < Jump to prev comment mark
      > Jump to next comment mark
      m Insert new comment mark
      c Clear the special clipboard
      x Pop the newest content in special clipboard
      P Paste from special clipboard
      y Yank for special clipboard
      Y Yank in region for special clipboard
    • (sniem-shift)

      This function normally be binded to TAB in some mode’s keymaps. (Expect the insert mode keymap) And there’s a motion list (called shift-motion-list at below) which be linked to this function, it’s: sniem-forward-char, sniem-backward-char, sniem-next-line, sniem-prev-line, sniem-next-word, sniem-prev-word, sniem-scroll-up-command. Then, there’re three conditions you execute this function.

      1. Press TAB (The key which binds sniem-shift ) once

        When you just press once, this function is a replacement of shift. e.g.: You can execute the command of K by execute sniem-shift & k . Defaultly, it can be TAB k .

        But when you pressed a capital letter key after executing the function, in addition, the command of its lower case letter is a motion in shift-motion-list , the motion will be added or deleted from the motion-shift-locked key list.

      2. Press twice

        When you execute it twice, it’ll enter the motion-shift-locked mode. In this case, when you press the key of motions included in shift-motion-list , it will execute the motion of its capital letter key. And normally, only the first four motions of shift-motion-list are the in the motion-shift-locked mode key list. If you want to add or delete a motion from this mode, you just need to press its capital letter key. You can exit motion-shift-locked mode by press it twice.

      3. Press three times

        In this case, it will enter the Caps_Lock mode only in sniem insert mode. The effect is just like caps-lock (another package). You can press 3 times to exit this mode.

Some special operations

  • Motions
    • (sniem-goto-prev) & (sniem-goto-next)

      Use middle-keyboard to get the lines to forward or backward, then execute it.

    • (sniem-next-word) & (sniem-prev-word)

      Normally, goto the next or previous word. If there is a content selected, goto the next or previous content same as it.

    • (sniem-goto-last-point)

      Normally, goto the last-point. If the sniem-mark-content is exists, goto the mark-content.

    • (sniem-beginning-of-line)

      Normally, goto the beginning of current line. If the cursor is at beginning now, execute indentation function.

  • Editing operations
    • operation-about-last-point

      Most of the editing operations is related to last-point (Without (sniem-paste)).

      • You can press p after the operations to execute it with last-point.
      • (sniem-lock-unlock-last-point) Lock or unlock the last-point. When it is locked, it will display in the buffer.
    • operation-in-region

      All of the operations which are end with -in-region will edit the area from the forward point of the start of region to the backward point of the end of the region.

    • object-catch

      Sniem provides functions to get the object smartly: object-catch.

      • <RET>

        Get the closest pair to cursor.

      • <M-RET>

        Get the parent pair of the selected pair.

      • <C-RET>

        Input the char of the pair, then get the closest to cursor.

      • <C-M-RET>

        Input the char of the pair, then get the parent of the selected pair.

      • ( & [ & {

        Quickly get the pair.

    • (sniem-paste)

      Defaultly, press p to enter the interface of the sniem-paste. Then you can use n & p to flip. You can paste the first content when you press p in the first page. [1-9] to select the content.

    • (sniem-macro)

      Sniem provides some great kmacro functions.

      • Basic

        q for record, e for execution, n to name the last kmacro, l for lock or unlock the macro, . for forcibly lock macro, c for call macro.

      • Advance
        • When you record after selecting some lines, the kmacro will be executed to all the lines you selected after recording.
        • If you record after selecting content in the same line, the content will be recorded. Then you can execute (sniem-next-word) or (sniem-prev-word) to goto the next or previous content same as it. Execute (keyboard-quit) can cancel the content record.
    • (sniem-search)

      Normally, searching the original content you input. When you give it prefix argument, the content will be packed with regexp for finding symbol automatically.

    • (sniem-mark) Expand

      When you use this function to mark symbol, if there’re some expand attachment of current mode in sniem-mark-attachments (custom part will introduce it) around current selection, you can execute mark function again to expand selection.

      For example, when you writing Python, you can execute mark function (mark symbol) twice to select self.test .

    • sniem-mark-jump

      sniem-mark-jump provides two motions. They are (sniem-mark-jump-next) & (sniem-mark-jump-prev). Normally, execute them can goto the next or previous comment mark. But if you use them with digit-argument, they’ll find the next or previous comment mark with type which is the number you input of the mark type alist.

Custom

  • sniem-center-message & sniem-mark-message , etc.

    Theses variables are the help message for their operations. If you don’t want them, you can execute this function:

    (setq sniem-center-message nil
          sniem-mark-message nil
          sniem-delete-message nil
          sniem-change-message nil
          sniem-yank-message nil
          sniem-macro-message nil
          sniem-pair-message nil)
        
  • sniem-xxx-mode-cursor

    The xxx can be: normal, insert, motion.

  • sniem-motion-hint-sit-time

    This is the sit time for motion hint. Default is 1.

  • State Hint

    If you use awesome-tray, sniem will automaticly set (sniem-state) to the alist, so you can use it. Otherwise, you can set the state hint accroding to your modeline.

    If you use the default modeline, you can try this:

    (setq-default mode-line-format (append '((:eval (sniem-state))) mode-line-format))
    (force-mode-line-update)
        
  • sniem-mark-jump
    • sniem-mark-jump-author-name

      This is the author name for the comment mark.

    • sniem-mark-jump-author-name-enable

      This variable is the status of the author name’s enablement.

  • sniem-mark-attachments

    When marking symbol, sniem will try getting attachment from this variable. If the pair under cursor is in this variable, it will be regarded as a part of symbol. To set this variable, you can use function (sniem-mark-set-attachment) . e.g.:

    (sniem-mark-set-attachment 'global "_")
    (sniem-mark-set-attachment 'emacs-lisp-mode "<" ">")
    (sniem-mark-set-attachment
     'c-mode
     :expand '("::")
     ;; Normally, if the expand attachment is one char, it will only work for once.
     ;; But if you set it to more chars, the attachment will work like a normal attachment.
     )
    (sniem-mark-set-attachment
     'python-mode
     :expand '(".")                         ;For expand
     )
        
  • sniem-object-catch-global-symbol-alist

    This variable is the list of pairs which can be catched. And this variable can also provide pair info to (sniem-mark) & (sniem-pair) . This variable includes some global pairs and some pairs for specific modes.

    You can set this by (add-to-list) to add global pairs or (sniem-object-catch-mode-defalist) to set for certain mode. e.g.:

    (add-to-list 'sniem-object-catch-global-symbol-alist '("^" . "^"))
    
    (sniem-object-catch-mode-defalist emacs-lisp-mode
      ("`" . "'")
      ("'" . ""))                           ;Set the back-pair to empty string, means to remove it from pair-list
        
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化