changeset 577:c903e43d0e1a

Use line-end-position for safe work, fix issue when operate on last line.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Mon, 29 Sep 2014 10:19:58 +0300
parents 3e30e60c9f51
children 7948fb9d0ced
files misc/cleanupdoc-find-dup.el
diffstat 1 files changed, 10 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/misc/cleanupdoc-find-dup.el	Thu Aug 28 15:02:35 2014 +0300
+++ b/misc/cleanupdoc-find-dup.el	Mon Sep 29 10:19:58 2014 +0300
@@ -6,26 +6,18 @@
 
   (local-set-key [C-return] 'my-help)"
   (interactive)
-  (let ( (curr (line-number-at-pos)) file beg end )
+  (let ( file beg end (inhibit-field-text-motion t) )
     (save-excursion
-      (search-forward " == ")
-      (cond
-       ((equal (line-number-at-pos) curr)
-        (setq end (- (point) 4))
-        (beginning-of-line)
-        (setq beg (point))
-        (setq file (buffer-substring beg end))
-        )
-       (t
-        (search-backward "\n")
-        (setq end (point))
-        (search-backward " == ")
+      (if (search-forward " == " (line-end-position) t)
+          (progn
+            (setq end (- (point) 4))
+            (setq beg (line-beginning-position))
+            (setq file (buffer-substring beg end)))
+        (setq end (line-end-position))
+        (search-backward " == " (line-beginning-position))
         (setq beg (+ (point) 4))
-        (setq file (buffer-substring beg end))
-        )
-      ))
+        (setq file (buffer-substring beg end))) )
     ;; (message "%s" file)
     (delete-file file)
-    (kill-whole-line)
-    ))
+    (kill-whole-line) ))