summaryrefslogtreecommitdiff
path: root/.emacs.d/mysnippets/text-mode/emacs-lisp-mode
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/mysnippets/text-mode/emacs-lisp-mode')
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/.read_me11
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/defun11
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/dired.process_marked16
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.process17
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.read-lines17
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/find-replace17
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabstring4
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabthing4
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/traverse_dir6
-rw-r--r--.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region27
10 files changed, 130 insertions, 0 deletions
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/.read_me b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/.read_me
new file mode 100644
index 0000000..9e6e532
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/.read_me
@@ -0,0 +1,11 @@
1TITLE: Emacs Idiom Template Set. Version 1. 2009-02-22
2
3DESCRIPTION: Some useful templates for emacs lisp. This template set is based on useful elisp idioms on common tasks.
4
5LICENSING: GPL version 3.
6
7AUTHOR: Xah Lee
8
9Home Page: latest version at:
10• Emacs Lisp Idiom Templates
11 http://xahlee.org/emacs/elisp_idiom_templates.html
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/defun b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/defun
new file mode 100644
index 0000000..0105d20
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/defun
@@ -0,0 +1,11 @@
1#name : function template
2#contributor : Xah Lee
3# --
4(defun $1 ()
5 "thisandthat."
6 (interactive)
7 (let (var1)
8 (setq var1 some)
9 $0
10 )
11) \ No newline at end of file
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/dired.process_marked b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/dired.process_marked
new file mode 100644
index 0000000..1b42597
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/dired.process_marked
@@ -0,0 +1,16 @@
1#name : process marked files in dired
2#contributor : Xah Lee
3# --
4;; idiom for processing a list of files in dired's marked files
5
6;; suppose myProcessFile is your function that takes a file path
7;; and do some processing on the file
8
9(defun dired-myProcessFile ()
10 "apply myProcessFile function to marked files in dired."
11 (interactive)
12 (require 'dired)
13 (mapc 'myProcessFile (dired-get-marked-files))
14)
15
16;; to use it, type M-x dired-myProcessFile
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.process b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.process
new file mode 100644
index 0000000..abd1a33
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.process
@@ -0,0 +1,17 @@
1#name : a function that process a file
2#contributor : Xah Lee
3# --
4(defun doThisFile (fpath)
5 "Process the file at path FPATH ..."
6 (let ()
7 ;; create temp buffer without undo record or font lock. (more efficient)
8 ;; first space in temp buff name is necessary
9 (set-buffer (get-buffer-create " myTemp"))
10 (insert-file-contents fpath nil nil nil t)
11
12 ;; process it ...
13 ;; (goto-char 0) ; move to begining of file's content (in case it was open)
14 ;; ... do something here
15 ;; (write-file fpath) ;; write back to the file
16
17 (kill-buffer " myTemp")))
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.read-lines b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.read-lines
new file mode 100644
index 0000000..b4a1942
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/file.read-lines
@@ -0,0 +1,17 @@
1#name : read lines of a file
2#contributor : Xah Lee
3# --
4(defun read-lines (filePath)
5 "Return a list of lines in FILEPATH."
6 (with-temp-buffer
7 (insert-file-contents filePath)
8 (split-string
9 (buffer-string) "\n" t)) )
10
11;; process all lines
12(mapc
13 (lambda (aLine)
14 (message aLine) ; do your stuff here
15 )
16 (read-lines "inputFilePath")
17) \ No newline at end of file
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/find-replace b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/find-replace
new file mode 100644
index 0000000..cefcf51
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/find-replace
@@ -0,0 +1,17 @@
1#name : find and replace on region
2#contributor : Xah Lee
3# --
4(defun replace-html-chars-region (start end)
5 "Replace “<” to “&lt;” and other chars in HTML.
6This works on the current region."
7 (interactive "r")
8 (save-restriction
9 (narrow-to-region start end)
10 (goto-char (point-min))
11 (while (search-forward "&" nil t) (replace-match "&amp;" nil t))
12 (goto-char (point-min))
13 (while (search-forward "<" nil t) (replace-match "&lt;" nil t))
14 (goto-char (point-min))
15 (while (search-forward ">" nil t) (replace-match "&gt;" nil t))
16 )
17 )
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabstring b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabstring
new file mode 100644
index 0000000..55600b1
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabstring
@@ -0,0 +1,4 @@
1#name : grab buffer substring
2#contributor : Xah Lee
3# --
4(setq $0 (buffer-substring-no-properties myStartPos myEndPos))
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabthing b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabthing
new file mode 100644
index 0000000..772b8dc
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/grabthing
@@ -0,0 +1,4 @@
1#name : grab word under cursor
2#contributor : Xah Lee
3# --
4(setq $0 (thing-at-point 'symbol))
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/traverse_dir b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/traverse_dir
new file mode 100644
index 0000000..2859cbd
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/traverse_dir
@@ -0,0 +1,6 @@
1#name : traversing a directory
2#contributor : Xah Lee
3# --
4;; apply a function to all files in a dir
5(require 'find-lisp)
6(mapc 'my-process-file (find-lisp-find-files "~/myweb/" "\\.html$"))
diff --git a/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region
new file mode 100644
index 0000000..66a59e4
--- /dev/null
+++ b/.emacs.d/mysnippets/text-mode/emacs-lisp-mode/word-or-region
@@ -0,0 +1,27 @@
1#name : Command that works on region or word
2#contributor : Xah Lee
3# --
4;; example of a command that works on current word or text selection
5(defun down-case-word-or-region ()
6 "Lower case the current word or text selection."
7(interactive)
8(let (pos1 pos2 meat)
9 (if (and transient-mark-mode mark-active)
10 (setq pos1 (region-beginning)
11 pos2 (region-end))
12 (setq pos1 (car (bounds-of-thing-at-point 'symbol))
13 pos2 (cdr (bounds-of-thing-at-point 'symbol))))
14
15 ; now, pos1 and pos2 are the starting and ending positions
16 ; of the current word, or current text selection if exists
17
18 ;; put your code here.
19 $0
20 ;; Some example of things you might want to do
21 (downcase-region pos1 pos2) ; example of a func that takes region as args
22 (setq meat (buffer-substring-no-properties pos1 pos2)) ; grab the text.
23 (delete-region pos1 pos2) ; get rid of it
24 (insert "newText") ; insert your new text
25
26 )
27)