-
Notifications
You must be signed in to change notification settings - Fork 17
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
Keep colors and add Org mode support #23
base: master
Are you sure you want to change the base?
Conversation
Rather than using face-remap for efficient dimming and restoring colors in the focused area, just dim /visible/ text in the unfocused region. The main argument for this approach is that there are many corner cases in restoring the colors correctly, and inaccuracies in the coloring is less crucial in the unfocused area.
I'll will try this branch now. Thanks for sharing it! |
Any problems so far @ReneFroger? I’m leaning towards merging and releasing soon. |
You weren't kidding! :) I'm sorry to report that this is probably not usable in its current state. I loaded my main personal Org file into a clean Emacs, ran However, when I copied only those lines into a separate Org file, without the several large subtrees after them, performance seemed fine. Maybe the |
BTW, I understand basically why you do this, but I think it's inappropriate to do so when the file is loaded, as that's out of the package's scope: (put 'org-element 'bounds-of-thing-at-point
#'focus-org-element-bounds) |
Also, it seems bogus to be running this on every movement command: (defun focus-get-thing ()
"Return the current thing, based on `focus-mode-to-thing'."
(or focus-current-thing
(let* ((modes (mapcar 'car focus-mode-to-thing))
(mode (or (cl-find major-mode modes)
(apply #'derived-mode-p modes))))
(if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence)))) Calling |
BTW, I'm noticing some--what seems to me like--strange behavior with
It shows that For convenience, I'm using this function for profiling: (cl-defun profiler-start-stop-report (&optional (mode 'cpu+mem))
(interactive (list (if current-prefix-arg
'cpu
'cpu+mem)))
(if (profiler-running-p)
(progn
(profiler-report)
(profiler-stop))
(profiler-start mode)))
(define-key global-map (kbd "<f1>") #'profiler-start-stop-report) So, e.g.:
|
Thank you @alphapapa! I'm glad I held off on merging. A full second is not an acceptable amount of lag. In the most recent version (9af4fbe) the lag was not noticeable on the Org-files I tested.
Org-mode is problematic because it has a lot of invisible text displayed within the bounds of the window. Focus does ignore all invisible text, but it seems that the function that identifies the invisible regions (
Here I used the same approach as lsp-mode. It does seem to be the intended way of customizing
Profiling has provided useful and reasonable results when I've used it, and I have not seen results like the ones you report. I'll try to reproduce it. As for Edebug, my guess is that the function does nothing when you try to step through because it is wrapped in a Thank you again for the very useful and detailed feedback! It might be that the approach simply doesn't scale. In that case, I'll either have to
I hope to find a scalable way of doing this, using roughly the same approach. Either way, I'll be sure not to merge anything before things can run smoothly with more or less any emacs buffer (perhaps with the exception of files that are very slow with emacs by default (e.g. minified js files)). |
Yeah, the Org file I tested it on is 576 KB and 12k lines. I have larger ones, though. :)
This might be a silly idea, but what if you removed the checks for invisible text? Is that really necessary? In this case, there were large subtrees that were fully collapsed, i.e. only the top-level headings were visible, which means a lot of invisible text. Maybe checking for invisible text (at least, in Org buffers) is more work than necessary. Like I said, maybe a silly idea; I haven't tested it, and you know this code better than I do.
Hmm, okay. You might consider proposing a patch upstream to Org or Emacs then, because that seems like it should already be a thing, and then you wouldn't need to do it here.
Yeah, that was really weird. It was in a clean Emacs config (using
Aha. Yeah, this is one of the areas that gets tricky in Emacs.
Have you considered using Here's another idea that might work in conjunction with Let me know if I can help more. I haven't used this package yet, but I'm keen to try it on my Org files if it becomes usable. |
This pull request mainly addresses #2. It calculates a suitable foreground color for the region out of focus.
Doing this is significantly more resource demanding, so some effort has been made to avoid redundant computations. This includes to only recalculate when the focused area changes, only change the colors within the bounds of the window and ignore all invisible text (which can typically occur in Org-mode buffers with hidden subtrees).
The changes require a user to explicitly set a foreground in the
focus-unfocused
face when using Focus without a theme (#21 ). The reason for this is to allow this feature to co-exist with other customizations of thefocus-unfocused
andfocus-focused
faces (e.g. changing the size of the unfocused text, or making the focused area bold).Additionally, using Focus with Org-mode has been improved, by using org-element to provide a reasonable chunk to Focus on.