Programmatically determine if any line terminates in a buffer?

I have an idea for a possible cool / probably stupid emacs script that would dynamically resize text to fill the free space.

One thing I cannot understand is how to query the current buffer to check if any lines are currently nested. How should I do it?

+4
source share
2 answers

You can check if any lines are completed in the current buffer using the following function:

(defun wrapped-lines-p ()
  (save-excursion
    (goto-char (point-min))
    (let ((long-line-regexp 
           (format "^.\\{%d\\}.+$" (window-body-width))))
      (search-forward-regexp long-line-regexp nil t))))

, . , . :

(defun wrapped-lines-p ()
  (let ((window-width-pixels (window-body-width nil t)))
    (> (car (window-text-pixel-size nil nil nil (1+ window-width-pixels)))
       window-width-pixels)))
+3

, " " , .

window, window-width:

(defun window-long-lines-p ()
  "Return t is any visible line in the current window is longer than window width."
  (save-excursion
    (move-to-window-line -1)
    (let ((end (point)) here
          found-long-line)
      (move-to-window-line 0)
      (while (and (not found-long-line)
                  (< (setq here (point)) end))
        (when (< (window-width)
                 (- (progn (forward-line 1)
                           (point))
                    here))
          (setq found-long-line t)
          (message "long line: %d" (1- (line-number-at-pos)))))
      found-long-line)))
+1

Source: https://habr.com/ru/post/1674321/


All Articles