emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Performance degradation from long lines


From: Alexander Shukaev
Subject: Re: Performance degradation from long lines
Date: Fri, 26 Oct 2018 17:34:02 +0200

Modes like `so-long' are not useful at all to resolve these issues (because, example it does not prevent the initial activation of the offending major mode, but rather only disables it afterwards). The only way I found to reliably mitigate the problem in an semi-automated manner consists of two parts. First,

(require 'longlines)
;;
(defcustom global-longlines-threshold
  line-number-display-limit-width
  "\
Maximum line length permitted before applying `longlines-mode'.

See `global-longlines-p'."
  :group 'longlines
  :type 'integer)
;;
(defun global-longlines-p
    (&optional buffer)
  "\
Test all lines of buffer BUFFER for `global-longlines-threshold'.

Return t if `global-longlines-threshold' is exceeded."
  (with-current-buffer (or buffer (current-buffer))
    (when (integerp global-longlines-threshold)
      (save-restriction
        (widen)
        (save-excursion
          (goto-char (point-min))
          (let ((inhibit-field-text-motion t))
            (catch 'break
              (while (not (eobp))
                (when (> (- (line-end-position 1) (point))
                         global-longlines-threshold)
                  (throw 'break t))
                (forward-line 1)))))))))
;;
;;;###autoload
(defun turn-on-longlines-mode-maybe ()
  (interactive)
  (when (global-longlines-p)
    (longlines-mode)))
;;
;;;###autoload
(define-globalized-minor-mode global-longlines-mode longlines-mode
  turn-on-longlines-mode-maybe
  :group 'longlines)
;;
(provide 'global-longlines)

and then configure

(add-hook 'after-init-hook #'global-longlines-mode)

Secondly,

(defgroup inhibit-set-auto-mode
  nil
  "Inhibit `set-auto-mode'."
  :group 'files
  :prefix 'inhibit-set-auto-mode-)
;;
(defcustom inhibit-set-auto-mode-functions
  nil
  "\
List of functions to be called to try to inhibit `set-auto-mode'.

Only used by `inhibit-set-auto-mode'.  If one of them returns
non-nil, inhibit `set-auto-mode' and the rest are not called."
  :group 'inhibit-set-auto-mode
  :type 'hook)
;;
(defun inhibit-set-auto-mode--around-advice
    (function &rest ...)
  (if (run-hook-with-args-until-success 'inhibit-set-auto-mode-functions)
      (let (enable-local-variables
            interpreter-mode-alist
            magic-mode-alist
            auto-mode-alist
            magic-fallback-mode-alist)
        (apply function ...))
    (apply function ...)))
;;
;;;###autoload
(define-minor-mode inhibit-set-auto-mode
  "\
Toggle inhibiting `set-auto-mode'.

With a prefix argument ARG, enable the mode if ARG is positive,
and disable it otherwise.  If called from Lisp, enable the mode
if ARG is omitted or nil.

See `inhibit-set-auto-mode-functions'."
  :group 'inhibit-set-auto-mode
  :global t
  (if inhibit-set-auto-mode
      (advice-add #'set-auto-mode
                  :around
                  #'inhibit-set-auto-mode--around-advice
                  '((depth . 100)))
    (advice-remove #'set-auto-mode
                   #'inhibit-set-auto-mode--around-advice)))
;;
(provide 'inhibit-set-auto-mode)

and then configure

(add-hook 'after-init-hook #'inhibit-set-auto-mode)

(defun inhibit-set-auto-mode-line-number-display-limit-function ()
  (and (integerp line-number-display-limit)
       (> (buffer-size) line-number-display-limit)))
(add-hook 'inhibit-set-auto-mode-functions
          #'inhibit-set-auto-mode-line-number-display-limit-function)

Regards,
Alexander



reply via email to

[Prev in Thread] Current Thread [Next in Thread]