r_emacs | Unsorted

Telegram-канал r_emacs - /r/emacs

-

This channel is a feed for r/emacs. @r_channels @reddit2telegram

Subscribe to a channel

/r/emacs

Using new emacs features to replicate other packages: tree-sitter + transient + repeat-mode = expand-region

Made something recently that I thought other people might like, really illustrates the power of the new emacs built-in packages. I have re-implemented a part of [expand-region](https://github.com/magnars/expand-region.el) for the new tree-sitter modes, using only a few lines of elisp and built-in packages. This is probably already in Mickey Peterson's excellent [combobulate](https://github.com/mickeynp/combobulate) package.

To use it, open a treesitter enabled buffer (say with `python-ts-mode`) and then hit `<C-return>`. Repeat invocations of `<return>` will expand the region, `-` will contract and `C-g` will reset and exit.

The code is pretty simple:

(defvar treesit--region-stack '())

(defun treesit-node-bounds-match-region-p (node beg end)
"Returns `t' if the bounds of the region marked `beg' and `end' match the bounds of `node'."
(and
(= beg (treesit-node-start node))
(= end (treesit-node-end node))))

(defun treesit-mark-bigger-node ()
"Expand selection to the parent of the smallest node containing the region."
(interactive)
(unless mark-active
(set-mark-command nil))
(unless (or (eq last-command 'treesit-mark-bigger-node) (eq last-command 'treesit-contract-region))
(setq treesit--region-stack nil))
(let* ((cur-node (treesit-node-on (region-beginning) (region-end)))
(next-node (if
;; check if the node containing the selection is already good
(not (treesit-node-bounds-match-region-p cur-node (region-beginning) (region-end)))
cur-node
(treesit-parent-until
cur-node
(lambda (n)
(not (treesit-node-bounds-match-region-p n (region-beginning) (region-end))))))))
(unless (null next-node)
(push (cons (region-beginning) (region-end)) treesit--region-stack)
(set-mark (treesit-node-end next-node))
(goto-char (treesit-node-start next-node)))))

(defun treesit-contract-region ()
"Contract a region to the last expansion."
(interactive)
(unless (null treesit--region-stack)
(let ((last-region (pop treesit--region-stack)))
(set-mark (cdr last-region))
(goto-char (car last-region)))))

(defun treesit-reset-region ()
"Reset region to before the first invocation of `treesit-mark-bigger-node'."
(interactive)
(unless (null treesit--region-stack)
(let ((last-region (car (last treesit--region-stack))))
(setq treesit--region-stack nil)
(set-mark (cdr last-region))
(goto-char (car last-region))
(when (= (car last-region) (cdr last-region))
(deactivate-mark)))))

(defvar-keymap treesit-mark-bigger-node-repeat-map
:doc "Repeatedly expand selection up tree sitter nodes."
:repeat (:exit (treesit-reset-region))
"<return>" #'treesit-mark-bigger-node
"-" #'treesit-contract-region
"C-g" #'treesit-reset-region)

(repeat-mode) ;; Get rid of me if you already invoke repeat-mode!
(bind-key "<C-return>" #'treesit-mark-bigger-node)

https://redd.it/1e18toz
@r_emacs

Читать полностью…

/r/emacs

Confused implementing programmed completion? A snippet to get you started

So I was recently fiddling with programmed completion and want to document it for posterity. There's no example snippet like this in the manual, and it'd have got me started much more easily.

(defvar my-coll '("foo" "fnord" "baz"))
(defun my-programmable-coll (str pred flag)
(let ((coll my-coll))
(cond
((eq flag nil)
(try-completion str coll pred))
((eq flag t)
(all-completions str coll pred))
((eq flag 'lambda)
(test-completion str coll pred))
((consp flag)
(completion-boundaries str coll pred (cdr flag)))
((eq flag 'metadata)
(completion-metadata str coll pred)))))

;; These are equivalent!
(completing-read "Pick: " my-coll)
(completing-read "Pick: " #'my-programmable-coll)

My use-case: now I can hardcode an affixation-function in the metadata, so that I do not need to let-bind completion-extra-properties every time I write a call to completing-read.

https://redd.it/1e0w6r0
@r_emacs

Читать полностью…

/r/emacs

Can't find an old comic about emacs productivity

Hey internet,

I remember once coming across a short 3 panel comic where someone's boss is marveling "How are you so productive? It must be a gift, it must be a superpower" and the person is saying "It's just emacs" over and over.


I need this jpeg and I know it's out there somewhere but I can't find it. Do you any of you freaks have this thing in your \~/Downloads? Pls resyndicate for me.

TY!

https://redd.it/1e0t633
@r_emacs

Читать полностью…

/r/emacs

How to create noncontiguous regions

Recently I found out that Emacs can deal with so-called noncontiguous regions. I cannot find very much information about these on the internet, the Emacs manual or the Emacs help system. But I'm curious about these noncontiguous regions and want to see if I can use them for something. As an example, something I want to do is to narrow to a noncontiguous region. But to be clear, narrowing to a noncontiguous region is not the problem I want solved here. I just want to learn how to use noncontiguous regions.

I'll try to define a clear question. If I want to create a noncontiguous region that contains the columns 4 to 7 on rows 1 and 2 then I can do this using a rectangular region(at least interactively, but I imagine I can recreate that in elisp too). But what if I want to create a noncontiguous region containing columns 4 to 7 on lines 1 and 3 but not line 2. Then I cannot use rectangular regions(as far as I know). Is there a way to do this? I'm not necessarily asking for an interactive way to do it. An elisp solution is fine and even prefered.

I've found the variable region-extract-function that perhaps could be useful, but I'm not sure how to use it. In particular, I don't know when the function that this variable is bound to is called.

I also found the library zones.el. But from the documentation it seems like it doesn't actually define noncontiguous regions, just something that looks and feels like noncontiguous regions. So this doesn't really satisfy my curiosity. And I'm mainly interested in learning the builtin functionality, so a third party package like this isn't really what I'm looking for.

https://redd.it/1e0khao
@r_emacs

Читать полностью…

/r/emacs

Package go-translate update to v3
https://github.com/lorniu/go-translate

https://redd.it/1e0bad4
@r_emacs

Читать полностью…

/r/emacs

Whats the purpose of splitting init.el in modules?

I am using org as my configuration for my init.el and using submodules for grouping functionality.... I thought the purpose of dividing in modules was for if a module was failing you could get the exact module failing but when something fails I just get something like "error at line 20" so I don't know which out of the 6 submodules/files which init.el calls is failing and if the module in question is say module 3, all modules after it do not load.

https://redd.it/1e0euij
@r_emacs

Читать полностью…

/r/emacs

Inconsistent indentation logic in LSP

Is there additional configuration needed when setting up lsp-mode with respect to the tab key for indenting?

I've noticed that my indentations are always inconsistent. For example, when editing a React typescript component, if i just hit <TAB>, or create a new line, it indents 4 spaces from the last line. But if I highlight the region and hit <TAB> then it seems to indent based on LSP rules and indents it by 2.

The same is true when I'm in C++ mode.
While writing, and hitting tab when I'm on the line, I get the following header:

#pragma once

namespace somenamespace {
class SomeClass {
public:
SomeClass()
private:
int someMember;
}
}


But if I highlight the buffer and hit <TAB>, or call lsp-format-region, then I end up with:

#pragma once

namespace somenamespace {
class SomeClass {
public:
SomeClass();

private:
int someMember;
}
} // namespace somenamespace

Which i assume is different because when I do that, it's calling clang-format (based on the fact that the endspace ending comment get added.)

Is there a way to make it so that indentations will use lsp to formatting rules if lsp mode is enabled?

https://redd.it/1e0aysl
@r_emacs

Читать полностью…

/r/emacs

org-mode Hide special characters/lines for better presentation?

So, as you know, we can mark a source block with #+begin_src, and we can enclose one-liners with = to highlight them.

https://preview.redd.it/rs659r62nqbd1.png?width=852&amp;format=png&amp;auto=webp&amp;s=347f07626af24cec82ce3b7025f81ee1b7fa4b45

But, in the help doc, those symbols seem to be hidden, and you can see highlights and blocks, but without special characters/lines.

https://preview.redd.it/7cx6cmwnmqbd1.png?width=2358&amp;format=png&amp;auto=webp&amp;s=4e045c9c0f6a8ba9193770dbc3fd5475359f573d

https://preview.redd.it/69op5coomqbd1.png?width=2886&amp;format=png&amp;auto=webp&amp;s=e1f506687874f9c75988b8a04e5409e35b860a18

Is it possible to do that in my org docs, so it looks like in the help example?

https://redd.it/1e03roh
@r_emacs

Читать полностью…

/r/emacs

Running different themes on GUI Emacs and TTY emacsclient, in the same process

I had a problem where I wanted to run one theme in my GUI Emacs, but a totally different theme if I started a TTY emacsclient connected to the GUI process. I figured out a couple different ways to do that, and wrote a blog post about them. Hopefully somebody finds it interesting or useful; I know I learned new things about how faces work!



https://redd.it/1dzpps9
@r_emacs

Читать полностью…

/r/emacs

Weekly Tips, Tricks, &c. Thread

This is a thread for smaller, miscellaneous items that might not warrant a full post on their own.

See this search for previous "Weekly Tips, Tricks, &c." Threads.

Don't feel constrained in regards to what you post, just keep your post vaguely, generally on the topic of emacs.

https://redd.it/1dzqf8g
@r_emacs

Читать полностью…

/r/emacs

Syntax highlighting in common lisp changes when adding a method qualifier

Method docstrings are syntax highlit just like functions when I do not add one of the :around, :before, :after qualifiers, but as soon as I do, the docstring changes color to that of a regular string, why is this?

https://redd.it/1dzoy3u
@r_emacs

Читать полностью…

/r/emacs

managing a bunch of terminals?

In my neovim days I was a diehard tmux fan. I haven't found any solutions in emacs to manage a bunch of different terminal windows. What do you use?

https://redd.it/1dzjw49
@r_emacs

Читать полностью…

/r/emacs

I am keeping an up to date ob-http fork
https://ag91.github.io/blog/2024/07/09/i-am-keeping-an-up-to-date-ob-http-fork/

https://redd.it/1dzfzto
@r_emacs

Читать полностью…

/r/emacs

Mac key bindings? H...how are y'all doing it? I feel like I'm using 6.

I just picked up a Mactop (not my FIRST, but I'm trying to seriously consider a primary platform change.)

Pulled down homebrew, then emacs, and...I'm just flummoxed.

I'm about 40 years used to "alt/control" on both sides of the space bar being "meta/ctrl".

How? Can I remap those for use with emacs? I naively thought I could just "describe-key" to see what it thought those were natively, then reassign them in .emacs, but...no go.

Point me, Obi Wan, to TFM that I may R it.

Thanks.

o7

https://redd.it/1dz6kdt
@r_emacs

Читать полностью…

/r/emacs

How can I re-select the project root dir after accidentally choosing the wring one?

&#x200B;

https://preview.redd.it/a1fnukfuofbd1.png?width=2216&amp;format=png&amp;auto=webp&amp;s=2273b153fa9a09d47fd82f783de5d60842b5bd41

https://redd.it/1dyv4y1
@r_emacs

Читать полностью…

/r/emacs

How do debug? : Emacs crashes on X11 screen unlock

I've been having this issue for going on about a year. It's pretty regular. Several times a week, when I unlock my screen (regolith3/X11/i3) Emacs will die immediately or as soon as it gets focus. It doesn't seem to dump a core file anywhere obvious and even if it did I'd have to learn how to debug a core file for Emacs.

Anybody have any advice on how to debug this?

-----

EDIT1: This Emacs is 30.x from the Guix emacs-next pacakge. TIL that you can guix install emacs-next --with-debug-info=emacs-next and Guix will recompile the package with debug symbols. Now how long is THAT going to take? ;)

-----

https://redd.it/1e17lg9
@r_emacs

Читать полностью…

/r/emacs

GNU emacs 29.3 on Ubuntu 24.04 LTS

Hello. I recently got a new PC (ASUS NUC 14 box) and Ubuntu 24.04 LTS with Cinnamon interface was installed. Now, when I installed the default version of GNU emacs (v29.3) via sudo apt install emacs, I got a peculiar problem. When I run emacs as the end user, I got the following error shown in the minibuffer:

Symbol’s function definition is void: eieio-defclass

When I run it with -q option, it works, but clearly my ~/.emacs.d/init.el file is not loaded. So, when I run: emacs -q --load ~/.emacs.d/init.el it works as usual. So, what is wrong here? Does GNU emacs by default first load and check some files before loading my ~/.emacs.d/init.el file? Thanks a lot for your help!!

https://redd.it/1e0v565
@r_emacs

Читать полностью…

/r/emacs

My config does things, and so do third party packages. How to make them play well together?

I understand the title may be vague or nonsensical. But I had to make one, and that was the best I could come up with. A longer version of my question follows.

I am an amateur Emacsist. I've got a solid understanding of all things *nix, lisp, and configuring a text editor (from prior vim experience). I've been eagerly building up a very comfortable .emacs for the past few months, and have been loving the experience in general. However, there is one thing that bothers me which I don't believe bothers others as much, if not at all: When I try to use some package that adds to or modifies the fundamental Emacs experience — something that modifies things like buffer management, text editing or whatnot — it often clashes with my own previous customizations or even default Emacs behavior.

For instance, If I were to use a modal editing package like Evil mode, I'd need to rebind keys to work correctly for every package I added. Think Magit for instance. Another time I faced a similar issue was when I tried popper.el. It's a great package, but It's job is to augment default buffer-handing behavior. I often ran into issues where a buffer created by a function from one package ended up in the wrong place due to popper. This is not a devastating problem as I could always just place the buffer where I want it manually, but that's the point, sort of.

I have a very large config, and adding anything that changes the fundamental experience of Emacs becomes a software project of its own with the involvement of design, and large refactors and whatnot. I wonder if that's the case with you guys.

Does anyone else have the same experience? Is this something I just have to settle for and solve bottom-up by solving the problems as they arise? Am I holding it wrong? I'd love to know you guys' thoughts

https://redd.it/1e0kfb6
@r_emacs

Читать полностью…

/r/emacs

Github copilot chat in emacs

Hi, I use github copilot every day thanks to https://github.com/copilot-emacs/copilot.el

But there is no chat support so I started to write it. After some days of work, here is the result : https://github.com/chep/copilot-chat.el

I need help to maintain and improve it. Feel free to submit issues and pull requests.

https://preview.redd.it/ynsp76u1oubd1.png?width=2560&amp;format=png&amp;auto=webp&amp;s=c1a20525cf2c58e498b6eb1179bd11a64727a368



https://redd.it/1e0jtdi
@r_emacs

Читать полностью…

/r/emacs

Text in a shape - Broken lines

https://preview.redd.it/es3i7cqhctbd1.png?width=762&amp;format=png&amp;auto=webp&amp;s=f0d9e1f00accb96aacc472c6b9456fc1daccf031

Details: https://lifeofpenguin.blogspot.com/2024/06/text-along-path-gnu-emacs.html#broken-lines

https://redd.it/1e0fsoh
@r_emacs

Читать полностью…

/r/emacs

I tried getting Magic to Checkout a specific Directory and it always checked out the entire branch. What am I missing?

Hey everyone,

I spent about an hour trying a myriad of things to get this to work. It seems like it should be a fairly straightforward thing for Magit yet I couldn't seem to get it to work.

I tried the -- flag on checkout and no matter what I tried, it would either only check a single file out or the entire branch.

Is it possibly a conflict with Evil, Vertico, etc? I'm grasping at straws here.

https://redd.it/1e0di8e
@r_emacs

Читать полностью…

/r/emacs

Is setting global-auto-revert-non-file-buffers to t necessary to keep dired directories updated?

Hello

I have a hook for dired and I changed the auto-revert-interval to 1

(add-hook 'dired-mode-hook
(lambda ()
(auto-revert-mode)))

(setq-default auto-revert-interval 1)


Is there any advantage to setting global-auto-revert-non-file-buffers to t, when all I am interested in is keeping my dired buffers up to date? Also is there any significant performance penalty to keeping the auto-revert-internal lower than the default of 5?

https://redd.it/1e03kfc
@r_emacs

Читать полностью…

/r/emacs

Consistent, Dynamic Access to Your Current Emacs Theme's Palette
https://aatmunbaxi.netlify.app/comp/dyn_custom_palette_access_technicolor/

https://redd.it/1dzvth2
@r_emacs

Читать полностью…

/r/emacs

New to emacs. How to get fonts working in Doom emacs?
https://redd.it/1dzu17k
@r_emacs

Читать полностью…

/r/emacs

CONSULT-GREP on a remote machine via TRAMP: no preview?

Hej fellows,

I recently noticed that I don't get a preview of grep matches when I am using CONSULT-GREP on a directory on a remote machine. However, I do get previews when I execute CONSULT-GREP on the locale machine.

Do you have any idea why this might be the case? Is there anything I can tweak to get it?

Have a good day, fellows :)

https://redd.it/1dzpse4
@r_emacs

Читать полностью…

/r/emacs

Python/Django

Are there any newer updates on the best way to use Emacs for Django development? It seems that most are 10+ years old or no longer in development?

https://redd.it/1dzng0p
@r_emacs

Читать полностью…

/r/emacs

Start a lisp subrepl from a stack frame?

I am using sly and every time I run into a bug I set up some breakpoints in my code to halt execution as I go. Is it possible to open a subrepl within the context of a given frame? This way I could look at the local variables and test out different changes to them. I have looked in the manual but all I could find was an eval in frame command, which is annoying for extensive probing.

https://redd.it/1dyy7ev
@r_emacs

Читать полностью…

/r/emacs

one-tab-per-project (aka. otpp), workspace management via a thin layer between built-in project and tab-bar

Hi folks,

I've been searching for a package that enables the simple "one tab per project" workflow, so each project is isolated in its tab.

I used tabspaces for some time but I faced several issues with it. Then, I switched to the more lightweight project-tab-groups which creates a "tab group" per project, but with some limitations. The latter was simple enough to inspire me to create the package I'm looking for, `one-tab-per-project` (or otpp).

The idea is simple, install the package and its dependency `unique-dir-name` (another package of mine, created specifically for otpp), enable otpp-mode and you are good to go. Whenever you switched to a project project-switch-project (C-x p p), otpp will switch to a dedicated tab. And in case of conflicting projects names, otpp will resolve the conflict by renaming the similar tabs.

- https://github.com/abougouffa/one-tab-per-project
- https://github.com/abougouffa/unique-dir-name

Looking for your feedback!

https://redd.it/1dzdlqt
@r_emacs

Читать полностью…

/r/emacs

Alvaro Ramirez: Inline previous result and why you should edebug
https://xenodium.com/inline-previous-result-and-why-you-should-edebug/

https://redd.it/1dz1n42
@r_emacs

Читать полностью…

/r/emacs

Org-mode file+function+headline possible???

Hi there i am using org-reverse-datetree package and i am trying to do something like this but i think its not done the way I am doing it can you please help

          ("jw" "weekly Journal")
("jwi" "Weekly Journal Entry" plain
(file+function+headline "~/Sync/org/weekly_journal.org"
org-reverse-datetree-goto-date-in-file "Weekly Plan")
"\n %?"
)



https://redd.it/1dyu6c7
@r_emacs

Читать полностью…
Subscribe to a channel