]> code.delx.au - gnu-emacs-elpa/commitdiff
Set company-added-newline to t if the buffer was modified
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 6 Feb 2014 05:03:26 +0000 (07:03 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 6 Feb 2014 05:03:26 +0000 (07:03 +0200)
Fixes #58

company.el

index c2df4cfe7a0b0d3a449cf2bd10b20979d65551c3..0b7ab89d5d78f4e84960ede010a9639c6e244890 100644 (file)
@@ -1177,9 +1177,11 @@ Keywords and function definition names are ignored."
   (or (and company-candidates (company--continue))
       (and (company--should-complete) (company--begin-new)))
   (when company-candidates
-    (when (and company-end-of-buffer-workaround (eobp))
-      (save-excursion (insert "\n"))
-      (setq company-added-newline (buffer-chars-modified-tick)))
+    (let ((modified (buffer-modified-p)))
+      (when (and company-end-of-buffer-workaround (eobp))
+        (save-excursion (insert "\n"))
+        (setq company-added-newline
+              (or modified (buffer-chars-modified-tick)))))
     (setq company-point (point)
           company--point-max (point-max))
     (company-ensure-emulation-alist)
@@ -1192,7 +1194,8 @@ Keywords and function definition names are ignored."
        (let ((tick (buffer-chars-modified-tick)))
          (delete-region (1- (point-max)) (point-max))
          (equal tick company-added-newline))
-       ;; Only set unmodified when tick remained the same since insert.
+       ;; Only set unmodified when tick remained the same since insert,
+       ;; and the buffer wasn't modified before.
        (set-buffer-modified-p nil))
   (when company-prefix
     (if (stringp result)