Use Emacs as a code snippet management tool

Source: Internet
Author: User

I. Requirements

The basic functions required by a code snippet management tool include:

  1. Supports multi-language highlighting

  2. Saves the description of the Code.

  3. Tag tags supported

  4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.