Emacs-langtool icon indicating copy to clipboard operation
Emacs-langtool copied to clipboard

Checking a narrowed org subtree confuses langtool

Open brandelune opened this issue 8 years ago • 3 comments

Open a narrowed org subtree in a separate window or frame and launch langtool-check.

The highlighted areas will be shifted to a position that counts from the beginning of the original buffer, not of that narrowed buffer.

So all the highlighted areas will not correspond to the area that has a problem and the correction will be applied to the wrong area.

brandelune avatar Sep 23 '17 02:09 brandelune

Open a narrowed org subtree in a separate window or frame and launch langtool-check.

The highlighted areas will be shifted to a position that counts from the beginning of the original buffer, not of that narrowed buffer.

So all the highlighted areas will not correspond to the area that has a problem and the correction will be applied to the wrong area.

Having the same problem. I thought it was an issue with my setup, but being able to check on only one section of an org file would be great. Not a deal breaker since you can widen out, but when you have a large org file and want to focus in a narrowed tree it would be nice to have langtool available as well.

dariusbdockery avatar Jun 02 '19 17:06 dariusbdockery

This could probably be easily patched by rewriting the way langtool-check-buffer checks for begin and end as follows:

@@ -1676,8 +1676,12 @@
   (langtool--check-command)
   ;; probablly ok...
   (let* ((region-p (langtool-region-active-p))
-         (begin (and region-p (region-beginning)))
-         (finish (and region-p (region-end))))
+	 (begin (cond 
+		 (region-p (region-beginning))
+		 (buffer-narrowed-p) (point-min)))
+	 (finish (cond
+		  (region-p (region-end))
+		  (buffer-narrowed-p) (point-max))))

This way, if the buffer is narrowed, a tmpfile is created similarly to how langtool.el handles an active region, but begin and finish will be nil if the buffer is not narrowed (and no region is active) thus bypassing tmpfile creation as was originally the case.

mapreducedog avatar Sep 30 '20 13:09 mapreducedog

another workaround is to define an advice that will simply mark whole buffer:

(define-advice langtool-check-buffer (:around (fn &optional lang) fix-narrowing)
  (save-mark-and-excursion
    (unless (use-region-p)
      (let ((inhibit-message t))
        (mark-whole-buffer)))
    (funcall fn lang)))

andreyorst avatar Jun 12 '22 16:06 andreyorst