mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
Added some snippets for elisp-mode from Xah Lee.
This commit is contained in:
parent
28aacbc7c1
commit
84ac5bd613
11
snippets/text-mode/emacs-lisp-mode/.read_me
Normal file
11
snippets/text-mode/emacs-lisp-mode/.read_me
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
TITLE: Emacs Idiom Template Set. Version 1. 2009-02-22
|
||||||
|
|
||||||
|
DESCRIPTION: Some useful templates for emacs lisp. This template set is based on useful elisp idioms on common tasks.
|
||||||
|
|
||||||
|
LICENSING: GPL version 3.
|
||||||
|
|
||||||
|
AUTHOR: Xah Lee
|
||||||
|
|
||||||
|
Home Page: latest version at:
|
||||||
|
• Emacs Lisp Idiom Templates
|
||||||
|
http://xahlee.org/emacs/elisp_idiom_templates.html
|
11
snippets/text-mode/emacs-lisp-mode/defun
Normal file
11
snippets/text-mode/emacs-lisp-mode/defun
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#name : function template
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
(defun $1 ()
|
||||||
|
"thisandthat."
|
||||||
|
(interactive)
|
||||||
|
(let (var1)
|
||||||
|
(setq var1 some)
|
||||||
|
$0
|
||||||
|
)
|
||||||
|
)
|
16
snippets/text-mode/emacs-lisp-mode/dired.process_marked
Normal file
16
snippets/text-mode/emacs-lisp-mode/dired.process_marked
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#name : process marked files in dired
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
;; idiom for processing a list of files in dired's marked files
|
||||||
|
|
||||||
|
;; suppose myProcessFile is your function that takes a file path
|
||||||
|
;; and do some processing on the file
|
||||||
|
|
||||||
|
(defun dired-myProcessFile ()
|
||||||
|
"apply myProcessFile function to marked files in dired."
|
||||||
|
(interactive)
|
||||||
|
(require 'dired)
|
||||||
|
(mapc 'myProcessFile (dired-get-marked-files))
|
||||||
|
)
|
||||||
|
|
||||||
|
;; to use it, type M-x dired-myProcessFile
|
17
snippets/text-mode/emacs-lisp-mode/file.process
Normal file
17
snippets/text-mode/emacs-lisp-mode/file.process
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#name : a function that process a file
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
(defun doThisFile (fpath)
|
||||||
|
"Process the file at path FPATH ..."
|
||||||
|
(let ()
|
||||||
|
;; create temp buffer without undo record or font lock. (more efficient)
|
||||||
|
;; first space in temp buff name is necessary
|
||||||
|
(set-buffer (get-buffer-create " myTemp"))
|
||||||
|
(insert-file-contents fpath nil nil nil t)
|
||||||
|
|
||||||
|
;; process it ...
|
||||||
|
;; (goto-char 0) ; move to begining of file's content (in case it was open)
|
||||||
|
;; ... do something here
|
||||||
|
;; (write-file fpath) ;; write back to the file
|
||||||
|
|
||||||
|
(kill-buffer " myTemp")))
|
17
snippets/text-mode/emacs-lisp-mode/file.read-lines
Normal file
17
snippets/text-mode/emacs-lisp-mode/file.read-lines
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#name : read lines of a file
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
(defun read-lines (filePath)
|
||||||
|
"Return a list of lines in FILEPATH."
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents filePath)
|
||||||
|
(split-string
|
||||||
|
(buffer-string) "\n" t)) )
|
||||||
|
|
||||||
|
;; process all lines
|
||||||
|
(mapc
|
||||||
|
(lambda (aLine)
|
||||||
|
(message aLine) ; do your stuff here
|
||||||
|
)
|
||||||
|
(read-lines "inputFilePath")
|
||||||
|
)
|
17
snippets/text-mode/emacs-lisp-mode/find-replace
Normal file
17
snippets/text-mode/emacs-lisp-mode/find-replace
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#name : find and replace on region
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
(defun replace-html-chars-region (start end)
|
||||||
|
"Replace “<” to “<” and other chars in HTML.
|
||||||
|
This works on the current region."
|
||||||
|
(interactive "r")
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region start end)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (search-forward "&" nil t) (replace-match "&" nil t))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (search-forward "<" nil t) (replace-match "<" nil t))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (search-forward ">" nil t) (replace-match ">" nil t))
|
||||||
|
)
|
||||||
|
)
|
4
snippets/text-mode/emacs-lisp-mode/grabstring
Normal file
4
snippets/text-mode/emacs-lisp-mode/grabstring
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#name : grab buffer substring
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
(setq $0 (buffer-substring-no-properties myStartPos myEndPos))
|
4
snippets/text-mode/emacs-lisp-mode/grabthing
Normal file
4
snippets/text-mode/emacs-lisp-mode/grabthing
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#name : grab word under cursor
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
(setq $0 (thing-at-point 'symbol))
|
6
snippets/text-mode/emacs-lisp-mode/traverse_dir
Normal file
6
snippets/text-mode/emacs-lisp-mode/traverse_dir
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#name : traversing a directory
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
;; apply a function to all files in a dir
|
||||||
|
(require 'find-lisp)
|
||||||
|
(mapc 'my-process-file (find-lisp-find-files "~/myweb/" "\\.html$"))
|
27
snippets/text-mode/emacs-lisp-mode/word-or-region
Normal file
27
snippets/text-mode/emacs-lisp-mode/word-or-region
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#name : Command that works on region or word
|
||||||
|
#contributor : Xah Lee
|
||||||
|
# --
|
||||||
|
;; example of a command that works on current word or text selection
|
||||||
|
(defun down-case-word-or-region ()
|
||||||
|
"Lower case the current word or text selection."
|
||||||
|
(interactive)
|
||||||
|
(let (pos1 pos2 meat)
|
||||||
|
(if (and transient-mark-mode mark-active)
|
||||||
|
(setq pos1 (region-beginning)
|
||||||
|
pos2 (region-end))
|
||||||
|
(setq pos1 (car (bounds-of-thing-at-point 'symbol))
|
||||||
|
pos2 (cdr (bounds-of-thing-at-point 'symbol))))
|
||||||
|
|
||||||
|
; now, pos1 and pos2 are the starting and ending positions
|
||||||
|
; of the current word, or current text selection if exists
|
||||||
|
|
||||||
|
;; put your code here.
|
||||||
|
$0
|
||||||
|
;; Some example of things you might want to do
|
||||||
|
(downcase-region pos1 pos2) ; example of a func that takes region as args
|
||||||
|
(setq meat (buffer-substring-no-properties pos1 pos2)) ; grab the text.
|
||||||
|
(delete-region pos1 pos2) ; get rid of it
|
||||||
|
(insert "newText") ; insert your new text
|
||||||
|
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user