logos icon indicating copy to clipboard operation
logos copied to clipboard

This is question - not a bug

Open srdasgupta opened this issue 1 year ago • 4 comments

Hi, Apologies for posting this question as an issue. I am guessing many programmers use logos and some may find this question useful. In case you dislike me posting questions here, I default to your preferred method. Question - how do I configure logos for programming? I use emacs with evil mode and few more plugins. I mostly use emacs for writing code (c, c++, go etc). I like what logos provides and want to configure so that end result is similar to zen mode in nvim. Can you please help guide me on how to configure logos for this purpose? Example scenario 1: Say, I want to select a region with visual mode and then run logos-focus-mode (I mapped it to C-c z), I want to see only the selected area. How can I configure logos to recognise the region (starting point, delimiter etc). Example scenario 2: When I am normal mode and inside a function and if I run logos-focus-mode, then only that function or the area within the indentation should be displayed by the logos. In this case, how do I configure the starting point, delimiter etc? FYI - On nvim, I use focus mode these days and I want to mix and match it with logos (I use twilight.nvim and sometimes combine it with zen mode if I am working on a big function). I am slowly but surely starting to adopt emacs as well.

srdasgupta avatar Mar 21 '23 16:03 srdasgupta

Hi, Apologies for posting this question as an issue. I am guessing many programmers use logos and some may find this question useful. In case you dislike me posting questions here, I default to your preferred method.

Hello @srdasgupta! I am fine with this approach. No worries!

Question - how do I configure logos for programming? I use emacs with evil mode and few more plugins. I mostly use emacs for writing code (c, c++, go etc). I like what logos provides and want to configure so that end result is similar to zen mode in nvim. Can you please help guide me on how to configure logos for this purpose?

Can you tell me more about zen mode? I am not familiar with it.

Example scenario 1: Say, I want to select a region with visual mode and then run logos-focus-mode (I mapped it to C-c z), I want to see only the selected area. How can I configure logos to recognise the region (starting point, delimiter etc).

logos uses the "page delimiters" to recognise the section. You can then narrow to it with M-x logos-narrow-dwim. Page delimiters can either be the ^L characters, which you input with C-q C-l (using default key bindings, else M-x quoted-insert and then C-l), or the outline of the document. In the latter case you can enable the user option logos-outlines-are-pages and then configure logos-outline-regexp-alist to use the pattern that works in the given major mode.

Note that major modes may already define an outline-regexp. This is a buffer-local variable. You can find its value by visiting the file you are interested in and doing M-: outline-regexp and then RET (or M-x eval-expression).

I can be more specific if you show me some sample file. I am not familiar with c, c++, go...

Example scenario 2: When I am normal mode and inside a function and if I run logos-focus-mode, then only that function or the area within the indentation should be displayed by the logos. In this case, how do I configure the starting point, delimiter etc? FYI - On nvim, I use focus mode these days and I want to mix and match it with logos (I use twilight.nvim and sometimes combine it with zen mode if I am working on a big function). I am slowly but surely starting to adopt emacs as well.

The logos-focus-mode does not automatically "narrow" for you. This is something you can do independently. What that mode does is to enable some extra stylistic tweaks.

FYI - On nvim, I use focus mode these days and I want to mix and match it with logos (I use twilight.nvim and sometimes combine it with zen mode if I am working on a big function). I am slowly but surely starting to adopt emacs as well.

Independent of logos, are you familiar with Emacs' narrowing commands? Such as M-x narrow-to-defun? Maybe they give you what you need.

protesilaos avatar Mar 26 '23 05:03 protesilaos

@srdasgupta I'm currently using logos exclusively as you describe, just the programming use case. You need to set the following logos option.

(setq logos-outlines-are-pages t)

And then set the variable outline-regexp.

(defun cc-config ()
 ;; Any number of tabs, and doxygen groups. 
  (setq-local outline-regexp "	*/// +\\(\\\\defgroup\\|\\\\addtogroup \\|.*\\)")
)
(add-hook 'c-mode-common-hook 'cc-config)

This way you can create sections in your codebase using comments (or other construct) as described by outline-regexp - I'm using tabs (inserted using C-q), so the heading with the least number of them is the top header. Then the logos page commands can be used ,they work really well and with little configuration.

For the examples mentioned you can use the narrow and widen commands. Example 1. C-space can be used to set the mark and delimit the region, then you can call narrow-to-region. Example 2. This is an interesting use case. I know that some evil commands can interact with the indentation level (maybe it was a text object extension), combining a command that selects by indentation level and then narrowing could achieve this (can't remember the exact evil command right now).

Edit: the combination v+i+{ and then narrow-to-region works in evil-mode. I'm not familiar with using evil programmatically, but at least a macro could be created and stored for this use case if required. Edit2: I fixed the initial regex It was missing the final delimiter. @protesilaos could it be possible to add some logos defun commands ?. I could submit this if it is within logos design. I find the logos commands superior to the process of manual narrowing.

MirkoHernandez avatar Mar 27 '23 00:03 MirkoHernandez

@MirkoHernandez

could it be possible to add some logos defun commands ?. I could submit this if it is within logos design. I find the logos commands superior to the process of manual narrowing.

There are some logos narrowing functions. I was not sure if people were using them so I did not develop them further. If you have any ideas, I am interested to learn about them.

protesilaos avatar Mar 27 '23 04:03 protesilaos

Just to clarify, the following is my usage of narrow before I started using logos

  • include outline-regexp in imenu-generic-expression.
  • use imenu to navigate to a section,
  • Then use the beginning and end of defun commands.
    • occasionally use narrow-to-defun.

Using logos:

  • use imenu, go to a section and then logos-narrow-dwim. ( This is really convenient and only possible using logos since there is no narrow equivalent)
  • use the logos page commands to navigate contiguous sections (or imenu again).
    • since the buffer now includes only related functions the scroll page commands can be used which are faster than the defun navigation commands.

A logos logos-backward-defun would work similar to logos-backward-page and be able to change function in the narrow state. Unfortunately I checked and some of the beginning-of-defun functions (the c version ) do not use a regexp (the emacs-lisp version does) so I'm not sure if it is possible a straightforward implementation ( It would require two different delimiters). Anyway this is really a minor consideration and a simple function that calls beginning-of-defun and then narrow-to-defun could be used for this use case.

MirkoHernandez avatar Mar 28 '23 01:03 MirkoHernandez