(defun uniquify-all-lines-region (start end) "Find duplicate lines in region START to END keeping first occurrence." (interactive "*r") (save-excursion (let ((end (copy-marker end))) (while (progn (goto-char start) (re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t)) (replace-match "\\1\n\\2")))))
(defun uniquify-all-lines-buffer () "Delete duplicate lines in buffer and keep first occurrence." (interactive "*") (uniquify-all-lines-region (point-min) (point-max)))
So for this buffer: Duplicate line 1 Unique line 1 Duplicate line 1 Unique line 2 Unique line 3 Duplicate line 1 Duplicate line 2 Duplicate line 2 Unique line 4
Running ‘M-x uniquify-all-lines-buffer’ produces: Duplicate line 1 Unique line 1 Unique line 2 Unique line 3 Duplicate line 2 Unique line 4
If you're a vi user, it's like 'dd'. I actually wrote the function because a friend of mine asked me "why doesn't emacs have 'dd'?" Well, now it does:
(defun kill-whole-line nil "kills the entire line on which the cursor is located, and places the cursor as close to its previous position as possible." (interactive) (progn (let ((y (current-column)) (a (progn (beginning-of-line) (point))) (b (progn (forward-line 1) (point)))) (kill-region a b) (move-to-column y))))
This function performs a syntax check on the php code testing for scripting errors.
;; PHP lint check ;; Assumes "php" is in $PATH (defun php-lint () "Performs a PHP lint-check on the current file." (interactive) (shell-command (concat "php -l " (buffer-file-name))))