;;; ---------------------------------------------------------------------- ;;; Make the first assignment operator on each line line up vertically ;;; ABCD = 2 ;;; A = 9 ;;; AB = 8 ;; The following little lump of lisp will ensure the first assignment operators ;; on each of the lines line up. This is part of our local formatting style ;; 'cos it looks nice ;-) ;; The style of the lisp however, is atrocious. All the problems come from ==, ;; which looks too much like 'op='. ;; Paul Hudson (defun align-equals (start end) "Make the first assignment operator on each line line up vertically" (interactive "*r") (save-excursion (let ((indent 0)) (narrow-to-region start end) (beginning-of-buffer) (while (not (eobp)) (if (find-assignment) (progn (exchange-point-and-mark) (setq indent (max indent (current-column))) (delete-horizontal-space) (insert " "))) (forward-line 1)) (beginning-of-buffer) (while (not (eobp)) (if (find-assignment) (indent-to-column (1+ (- indent (- (mark) (point)))))) (forward-line 1))) (widen))) ;; ;; Find an assignment statement ;; (defun find-assignment () (if (re-search-forward "[^<>=!]=\\|\\+=\\|-=\\|\\*=\\|/=\\|&=\\||=\\|\\^=\\|<<=\\|>>=" (save-excursion (end-of-line) (point)) t) (progn (goto-char (match-beginning 0)) (if (looking-at ".==") nil (if (looking-at "\\+=\\|-=\\|\\*=\\|/=\\|&=\\||=\\|\\^=\\|<<=\\|>>=") (set-mark (match-end 0)) (forward-char 1) (set-mark (1+ (point)))) (delete-horizontal-space) t)) nil)) ;;; ---------------------------------------------------------------------- ;;; Remove all ^M's from the buffer. (defun unix2dos-buffer () "Remove all ^M's from the buffer." (interactive) (^m-region (point-min) (point-max))) (defalias 'unix2dos 'unix2dos-buffer) (defun unix2dos-region (min max) "Remove all ^M's from the region." (interactive "r") (save-excursion (save-restriction (widen) (goto-char max) (while (re-search-backward "\C-m$" min t) (delete-char 1))))) (defun dos2unix (buffer) "Automate M-% C-q C-m RET C-q C-j RET" (interactive "b") (goto-char (point-min)) (while (search-forward (string ?\C-m) nil t) (replace-match (string ?\C-j) nil t))) ;;; ---------------------------------------------------------------------- ;;; Delete blank lines from the current buffer. (defun remove-blank-lines () "Delete blank lines from the current buffer." (interactive "*") (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward "^$") (kill-line))))) ;;; ---------------------------------------------------------------------- ;;; Delete heading whitespace from te current buffer (defun delete-heading-whitespace () "Delete all the heading whitespace across the current buffer. All whitespace before the first non-whitespace character in a line is deleted. This respects narrowing, created by \\[narrow-to-region] and friends. A formfeed is not considered whitespace by this function." (interactive "*") (save-match-data (save-excursion (goto-char (point-min)) (while (re-search-forward "^\\s-" nil t) (skip-syntax-backward "-" (save-excursion (forward-line 0) (point))) ;; Don't delete formfeeds, even if they are considered whitespace. (save-match-data (if (looking-at ".*\f") (goto-char (match-end 0)))) (delete-region (point) (match-end 0)))))) ;;; ---------------------------------------------------------------------- ;;; Remove HTML tags from the current buffer (defun strip-html () "Remove HTML tags from the current buffer, (this will affect the whole buffer regardless of the restrictions in effect)." (interactive "*") (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward "<[^<]*>" (point-max) t) (replace-match "\\1")) (goto-char (point-min)) (replace-string "©" "(c)") (goto-char (point-min)) (replace-string "&" "&") (goto-char (point-min)) (replace-string "<" "<") (goto-char (point-min)) (replace-string ">" ">") (goto-char (point-min))))) ;;; ---------------------------------------------------------------------- ;;; Up/Downcase html tags of the current buffer (defun rs-html-downcase-or-upcase-tags (&optional upcase) "Downcase html-tags in curent buffer. If given a prefix, upcase tags." (interactive "*P") (save-excursion (goto-char (point-min)) (let ((counter 0)) (while (re-search-forward ". Remove the big, green vegetable from my e-mail address... Requirements: * htmlize.el * wscript.exe must be installed and enabled * Microsoft Word must be installed Usage: Mark a region of fontified text, run this function and in a number of seconds you have the whole colorful text on your clipboard, ready to be pasted into a RTF-enabled application. " (interactive "r") (let ((snippet (buffer-substring START END)) (buf (get-buffer-create "*htmlized_to_clipboard*")) (script-file-name (expand-file-name "~/htmlized_to_clipboard.vbs")) (htmlized-file-name (expand-file-name "~/htmlized.html"))) (set-buffer buf) (delete-region (point-min) (point-max)) (insert snippet) (htmlize-buffer) (write-file htmlized-file-name) (delete-region (point-min) (point-max)) (setq htmlized-file-name (substitute ?\\ ?/ htmlized-file-name)) (insert (concat "Set oWord = WScript.CreateObject(\"Word.Application\")\n" "oWord.Documents.Open(\"" htmlized-file-name "\")\n" "oWord.Selection.HomeKey 6\n" "oWord.Selection.EndKey 6,1\n" "oWord.Selection.Copy\n" "oWord.Quit\n" "Set oWord = Nothing\n")) (write-file script-file-name) (kill-buffer "htmlized_to_clipboard.vbs") (setq script-file-name (substitute ?\\ ?/ script-file-name)) (w32-shell-execute nil "wscript.exe" script-file-name)))