Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] error in Emacs routine for removing duplicate lines



I had been using the below routine in Emacs (found on the web) for
removing duplicate lines in files for years, then it it suddenly stopped
working (probably as the result of some sort of upgrade).

When I try to run it, the error message is:

    Symbol's function definition is void: loop

Does this mean that the loop function is not contained in the version
of Emacs I am using (22.2.1)?

Chuck

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Remove duplicate lines in buffer;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun remove-duplicate-lines()
  (interactive)
  (save-excursion
    (let
        ((lines_hash (make-hash-table :test #'equal))
         (numlines (count-lines 1 (progn (end-of-buffer)(point)))))

      ;; Make a hash table with key=line 
      ;;     and value=the smallest line number that contains a line.
      (loop for i from numlines downto 1 do
           (let ((line nil))
             (goto-line i)
             (setf line (buffer-substring 
                         (progn (beginning-of-line) (point))
                         (progn (end-of-line) (point))))
             ;; Want to store the smallest line number for 
             ;;     a particular line.
             (setf (gethash line lines_hash) i)))
      ;; If a line has a line number not equal to the smallest line, kill it.
      (loop for i from numlines downto 1 do
           (let ((line nil))
             (goto-line i)
             (setf line (buffer-substring 
                         (progn (beginning-of-line) (point))
                         (progn (end-of-line) (point))))
             (beginning-of-line)
             (if (not (equal line ""))
                 (if (not (= 
                           (let ((min-line (gethash line lines_hash)))
                             (if (null min-line)
                                 -1
                               min-line))
                           i))
                     (kill-line 1))))))))
     



-------------------

A. Charles Muller

University of Tokyo
Graduate School of Humanities and Sociology, Faculty of Letters
Center for Evolving Humanities
7-3-1 Hongo, Bunkyo-ku
Tokyo 113-0033, Japan 

Web Site: Resources for East Asian Language and Thought
http://www.acmuller.net

<acmuller[at]jj.em-net.ne.jp>   

Mobile Phone: 090-9310-1787




Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links