From c13334d651b13d8b047cb3dc35ad3e1ef239013f Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 22 Oct 2009 05:30:58 +0200 Subject: added snippets for loading with module from dotfiles --- .../snippets/text-mode/emacs-lisp-mode/.read_me | 11 +++++++++ emacs.d/snippets/text-mode/emacs-lisp-mode/defun | 11 +++++++++ .../text-mode/emacs-lisp-mode/dired.process_marked | 16 +++++++++++++ .../text-mode/emacs-lisp-mode/file.process | 17 ++++++++++++++ .../text-mode/emacs-lisp-mode/file.read-lines | 17 ++++++++++++++ .../text-mode/emacs-lisp-mode/find-replace | 17 ++++++++++++++ .../snippets/text-mode/emacs-lisp-mode/grabstring | 4 ++++ .../snippets/text-mode/emacs-lisp-mode/grabthing | 4 ++++ .../text-mode/emacs-lisp-mode/traverse_dir | 6 +++++ .../text-mode/emacs-lisp-mode/word-or-region | 27 ++++++++++++++++++++++ 10 files changed, 130 insertions(+) create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/.read_me create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/defun create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/dired.process_marked create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/file.process create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/file.read-lines create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/find-replace create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/grabstring create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/grabthing create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/traverse_dir create mode 100644 emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region (limited to 'emacs.d/snippets/text-mode/emacs-lisp-mode') diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/.read_me b/emacs.d/snippets/text-mode/emacs-lisp-mode/.read_me new file mode 100644 index 0000000..9e6e532 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/.read_me @@ -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 diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/defun b/emacs.d/snippets/text-mode/emacs-lisp-mode/defun new file mode 100644 index 0000000..0105d20 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/defun @@ -0,0 +1,11 @@ +#name : function template +#contributor : Xah Lee +# -- +(defun $1 () + "thisandthat." + (interactive) + (let (var1) + (setq var1 some) + $0 + ) +) \ No newline at end of file diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/dired.process_marked b/emacs.d/snippets/text-mode/emacs-lisp-mode/dired.process_marked new file mode 100644 index 0000000..1b42597 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/dired.process_marked @@ -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 diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/file.process b/emacs.d/snippets/text-mode/emacs-lisp-mode/file.process new file mode 100644 index 0000000..abd1a33 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/file.process @@ -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"))) diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/file.read-lines b/emacs.d/snippets/text-mode/emacs-lisp-mode/file.read-lines new file mode 100644 index 0000000..b4a1942 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/file.read-lines @@ -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") +) \ No newline at end of file diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/find-replace b/emacs.d/snippets/text-mode/emacs-lisp-mode/find-replace new file mode 100644 index 0000000..cefcf51 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/find-replace @@ -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)) + ) + ) diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/grabstring b/emacs.d/snippets/text-mode/emacs-lisp-mode/grabstring new file mode 100644 index 0000000..55600b1 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/grabstring @@ -0,0 +1,4 @@ +#name : grab buffer substring +#contributor : Xah Lee +# -- +(setq $0 (buffer-substring-no-properties myStartPos myEndPos)) diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/grabthing b/emacs.d/snippets/text-mode/emacs-lisp-mode/grabthing new file mode 100644 index 0000000..772b8dc --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/grabthing @@ -0,0 +1,4 @@ +#name : grab word under cursor +#contributor : Xah Lee +# -- +(setq $0 (thing-at-point 'symbol)) diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/traverse_dir b/emacs.d/snippets/text-mode/emacs-lisp-mode/traverse_dir new file mode 100644 index 0000000..2859cbd --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/traverse_dir @@ -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$")) diff --git a/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region b/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region new file mode 100644 index 0000000..66a59e4 --- /dev/null +++ b/emacs.d/snippets/text-mode/emacs-lisp-mode/word-or-region @@ -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 + + ) +) -- cgit v1.2.3