-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: the guard-lf-intact-major-modes
where not taken into account
#2
Conversation
This PR fixes the issue mentioned below: While trying to add some modes (like `pcap-mode`) to `guard-lf-intact-major-modes`, I've noticed that it wasn't taken into account and that the mode was always changed to `fundamental-mode`. After a quick check, it turned out that `guard-lf-intact-major-modes` wasn't used correctly in `provided-mode-derived-p`, which needs the modes (`&rest modes`) to be provided as separate arguments and not as a list. The signature of the function: ``` emacs-lisp (provided-mode-derived-p MODE &rest MODES) ```
How about? (defun guard-lf--set-auto-mode-0 (fnc &rest args)
"Advice around the function `set-auto-mode-0'.
Arguments FNC and ARGS are used to call original operations."
(when guard-lf--detect-large-file
(setq guard-lf--detect-large-file nil) ; Revert back to `nil'
(when (and guard-lf-major-mode
- (not (provided-mode-derived-p (nth 0 args) guard-lf-intact-major-modes)))
+ (not (derived-mode-p (nth 0 args) guard-lf-intact-major-modes)))
(message "[INFO] Large file detected; use the `%s' as the new major mode"
guard-lf-major-mode)
(setf (nth 0 args) guard-lf-major-mode)))
(apply fnc args)) |
Well, it won't work for two reasons:
(derived-mode-p 'c-mode 'c++-mode 'python-mode) ;; Correct => it returns t if the current's buffer `major-mode` is derived from c-mode, c++-mode or python-mode
(derived-mode-p '(c-mode c++-mode 'python-mode)) ;; Incorrect => returns (almost) always nil
(provided-derived-mode-p major-mode 'c-mode 'c++-mode 'python-mode)
;; Is equivalent to:
(derived-mode-p 'c-mode 'c++-mode 'python-mode) So, even if we want to use The (apply #'+ '(1 2 3 4 5)) ; => 15
;; Is equivalent to:
(+ 1 2 3 4 5) ; => 15 While, doing: (setq l1 '(1 2)
l2 '(2 3 4 5))
(+ (car l1) l2) ; which is equivalent to what we have now in the code Is not a valid Elisp expression |
You can set up a test like this:
(setq large-file-warning-threshold 10000) ; 10k
(add-to-list 'guard-lf-intact-major-modes 'c-mode)
(add-to-list 'guard-lf-intact-major-modes 'c-ts-mode)
|
Thank you for your explanation. Sorry, I was a little busy and wasn't paying enough attention to this. 😓 |
Thanks for your responsiveness @jcs090218 ! |
This PR fixes the issue mentioned below:
While trying to add some modes (like
pcap-mode
) toguard-lf-intact-major-modes
, I've noticed that it wasn't taken into account and that the mode was always changed tofundamental-mode
.After a quick check, it turned out that
guard-lf-intact-major-modes
wasn't used correctly inprovided-mode-derived-p
, which needs the modes (&rest modes
) to be provided as separate arguments and not as a list.The signature of the function: