I. Requirements
The basic functions required by a code snippet management tool include:
Supports multi-language highlighting
Saves the description of the Code.
Tag tags supported
Convenient query
The Org-mode of Emacs can perfectly support these requirements.
II. Implementation
(Defvar mode-file-map '(C ++-mode. "cpp.org") (emacs-lisp-mode. "elisp.org") (Python-mode. "python.org") (Perl-mode. "perl.org") (DOS-mode. "bat.org") (Sh-mode. "bash.org") "ing the ing between major-mode and saving the code fragment file") (defvar code-library-path "D: /codelibrary/"" directory for storing code library files ") (defun save-code-to-Library () (interactive) (Let (Code (get-region-or-thing 'defun )) (library-file (Concat code-library-path (CDR (assoc major-mode-file-map )))) (Head (read-string "enter instructions for this Code ")) (Code-Major-mode (replace-Regexp-in-string "-mode $" (Format "% s" Major-mode )))) (When (string = library-file code-library-path) (setq library-file (Concat code-library-path "temp.org") (find-file library-file) (end-of-buffer) (newline) (insert (Concat "*" head) (newline-and-indent) (Insert (Concat "# + begin_src" code-Major-mode) (newline-and-indent) (Insert "# + end_src ") (Forward-line-1); last line (Org-edit-Src-Code) (insert Code) (Org-edit-Src-Exit) (Org-set-tags-command); set the code tags (save-buffer); (kill-buffer )))
Iii. Use
You can see in Emacs that the desired code is to be saved. You only need to select the code to be saved and then execute M-x save-code-to-library. emacs automatically selects an appropriate org file for saving based on the Code and the major-mode, and prompts you to enter the code description and tag.
Below is a code saved
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/48/63/wKioL1QHM6_wsHIIAADkrAYpJ_s627.jpg "Title =" Unnamed. jpg "alt =" wkiol1qhm6_wshiiaadkraypj_s627.jpg "/>Org-mode also provides a large number of search commands, which can be queried by TAG or content.
Use Emacs as a code snippet management tool