emacs - Programmatically detect if any line in a buffer is wrapping? -


i have idea possibly cool/probably stupid emacs script dynamically resize text fill available space.

one thing can't seem figure out how query current buffer see if lines being wrapped. how it?

you can check if lines wrapped in current buffer function this:

(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)))) 

as noted in comments, doesn't take account buffer's font size. since buffers can have mix of different sized fonts, window text pixel size needs tested. try this:

(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))) 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -