受够了每次向emacs粘贴xcode日志都要用keep-lines了。 (first-line-filter-mode)
来源:互联网 发布:gd32单片机 编辑:程序博客网 时间:2024/05/29 18:02
(defun first-line-filter (b e l) (save-excursion (goto-char (point-min)) ;goto first line (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) ;;use it as pattern (forward-line) (keep-lines line (point) (point-max)))))(define-minor-mode first-line-filter-mode "use the first line as filter whenever text insertion is happened." nil " *FL" nil (add-hook 'after-change-functions #'first-line-filter nil t));;之前傻乎乎地把keep-lines山寨了一遍,f**k;; (defun first-line-filter (b e l);; (save-excursion;; (goto-char (point-min)) ;goto first line;; (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) ;;use it as pattern;; (forward-line);; (forward-line) ;process other lines;; (while (not (eobp));; (if (string-match line (buffer-substring-no-properties (line-beginning-position) (line-end-position)));; (forward-line) ;skip matched line;; (progn (beginning-of-line) (delete-region (point) ;kill unmatched like grep;; (min (1+ (line-end-position)) (point-max)))))))))