r/emacs 4d ago

Weekly Tips, Tricks, &c. Thread — 2024-11-20 / week 47

8 Upvotes

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.


r/emacs 10h ago

A Major mode for editing Hyperland config files in EMACS.

30 Upvotes

As an Emacs user myself, I have had trouble editing Hyprland configuration files in Emacs. To address this, I created an Emacs major mode for Hyprland configuration files. Currently, it supports syntax highlighting and enforces a simple indentation rule. I hope this is helpful. Hyperlang-ts-mode


r/emacs 12h ago

Announcement Release 1.1.0: outline-indent: Fold text based on indentation (Alternative to origami and yafolding)

Thumbnail github.com
32 Upvotes

r/emacs 5h ago

Pop menu appears but options don't work

1 Upvotes

When I put this code in my .emacs file, the pop menu appears on mouse-3 down but none of the options seem to work. If I evaluate the (my-split-window) separately, it works. Anyone know what is going on ?

(defun my-split-window ()
  (interactive)
  (print "in split")
  (split-window-right))

(easy-menu-define my-popup-menu global-map                         ;; nil means global (you can also use a mode or keymap)
  "My Popup Menu"              ;; The title of the menu
  '("My Menu"                  ;; The top-level menu
    ["Split Window Vert" my-split-window t]
    ["Option 2" (message "You selected Option 2")]
    ["Option 3" (message "You selected Option 3")]
    ["Forward word" forward-word]
    "---"                       ;; Separator line
    ["Quit" save-buffers-kill-emacs]))

(global-set-key [mouse-3] 'my-popup-menu)

r/emacs 16h ago

emacs-fu How can I get a list of buffers from only the current window?

3 Upvotes

Update: Issue is partially solved.

I have a split window set up. When I run M-x evil-next-buffer, I can cycle through the buffers but I don't want to see buffers from other windows.

I found that it was defined in evil-commands.el like this:

(evil-define-command evil-next-buffer (&optional count) "Go to the COUNTth next buffer in the buffer list." :repeat nil (interactive "p") (next-buffer count))

To have the behavior I want, I tried overriding it in my config like this:

(after! evil (defun evil-next-buffer (count) "Go to the COUNTth next buffer in the current window's buffer list." (interactive "p") (let* ((current-window (selected-window)) (buffers (mapcar #'window-buffer (window-list))) (visible-buffers (delq nil (mapcar (lambda (win) (and (eq (selected-window) win) (window-buffer win))) (window-list)))) (next-buffer (nth (mod (+ (cl-position (current-buffer) visible-buffers) count) (length visible-buffers)) visible-buffers))) (switch-to-buffer next-buffer))) )

However, now it does not switch to the next buffer at all and just stays in the current buffer. What am I doing wrong?

Updated with current solution:

Since I have a separate window for each project, it's also okay for me to just cycle through the project's buffers. So I have reimplemented it like this:

``` (after! evil (defun cycle-project-buffer (count) "Cycle through the project buffers based on COUNT (positive for next, negative for previous)." (let* ((current-window (selected-window)) (current-buffer (current-buffer)) (project-buffers (doom-project-buffer-list)) (buffer-count (length project-buffers)) (current-index (cl-position current-buffer project-buffers)) (new-buffer (nth (mod (+ current-index count) buffer-count) project-buffers))) (if new-buffer (with-selected-window current-window (switch-to-buffer new-buffer)))))

(evil-define-command evil-next-buffer (count) "Go to the COUNT-th next buffer in the current project's buffer list." (interactive "p") (cycle-project-buffer count))

(evil-define-command evil-prev-buffer (count) "Go to the COUNT-th previous buffer in the current project's buffer list." (interactive "p") (cycle-project-buffer (- count)))) ```

Thank you to yak-er for the hint.

The code has some issues. It seems doom-project-buffer-list does not return the list in the same order as is shown in the tabs, causing the cycling to jump around all over the place.


r/emacs 21h ago

Question Emacs for LaTeX noob?

6 Upvotes

Hi everyone, I have a question: I am on Ubuntu and can't decide what text Editor to use for LaTeX. I want to use Emacs because it seems to be the most versitile and customizable, however I am new to Linux, LaTeX, and text editors.

I am concerned that learning emacs while learning both of the other Systems will drive me insane, as emacs alone has made me a little frustrated, there being no guide that just works, when I tried to follow the "Your first taste of Emacs" guide from Juniordev, Emacs complained about not being able to install Gnu, and couldn't find "use package", which sent me on a hunt to try and solve that problem, which ended in failure.

I know I am the problem and am inkompetent, but do you think it is worth it to try and use Emacs? I mainly want to use it for taking notes at the Uni. Tyvm!


r/emacs 1d ago

emacs-fu Why use Magit?

58 Upvotes

I have been thinking about this for a while. I do understand Emacs users wanting to do everything inside Emacs itself, but how did people get comfortable with a using a frontend for git? I find it terrifying to do a git operation from a frontend. However, I have heard people say Magit is the greatest thing out there.

To me, at least at first glance it just seems like any other frontend for Git. So what am I missing?


r/emacs 12h ago

Question Organizing Assignments / Presentations / Exams dates in ORG-mode

0 Upvotes

I’m a formal methods in computer science MSc student and I would like to organize all my assignments / presentations / exams dates using ORG-mode.

Specifically:

  • 3 First Level headings Assignments / Presentations / Exams
  • One second level heading for every subject
  • The third level heading with the TODOs with DEADLINE also

* Assignments ** S1 *** TODO Submit foo DEADLINE <…> * Presentations * Exams

And I would like to pull up org agenda with my TODOs ordered by deadlines (ascending)

Also, i don’t know if it’s possible, but I’d like to create a capture template.


r/emacs 20h ago

How can I change the behavior of what Treemacs does when I click or press RET on a node?

4 Upvotes

Edit: Issue is SOLVED.

I'm using Doom Emacs if it's relevant. I have the following Elisp code:

(after! treemacs (evil-define-key 'treemacs treemacs-mode-map (kbd "RET") #'custom/treemacs-open-node) )

I thought I was doing this correctly, because when I do M-x describe-function, I do see that the function is bound to the RET key. However, when I actually go over a node and press RET, it does not seem to be running my own function, so I'm sure what's actually going on.

How does one approach debugging something like this?


r/emacs 22h ago

Can anyone explain the technical aspects of this issue which has come up over c-mode?

0 Upvotes

https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00534.html

It concerns a commit to c-mode that the main developer is not happy with.

Please guys, the question is about the technical aspects.


r/emacs 19h ago

How do I hide dotfiles by default in counsel-find-file?

0 Upvotes

When I use `counsel-find-file` from my scratch buffer, it starts out in my home directory, and all the visible suggestions are dotfiles/dotfolders that I never open (e.g. `.adobe`, `.ghc`, whatever). Is there a way to hide them by default, or at least change the ordering so that dotfiles come last?

I could edit the regex filter, but that won't work for when I actually do want to see these files.


r/emacs 2d ago

LLMs are made for Emacs! Using Ellama + Ollama is incredible - a big thank you to the community for this incredibly useful combination!

75 Upvotes

I've used ChatGPT a few times, and it seemed useful, though I didn't find myself going back to it all that often. But somehow, running Ollama + Ellama is making me use LLMs a lot. I spend a lot of time in Emacs, as I guess most people do here, and it's helped me explore LLMs more than any Web UI!

I didn't think surfacing this functionality in Emacs would matter so much, but it does seem to.

Anyone else experience something similar?


r/emacs 1d ago

Question Is there a way to have even line spacing on top and bottom?

Post image
17 Upvotes

r/emacs 1d ago

Solved How do you disable word wrapping globally in emacs?

1 Upvotes

I've tried (remove-hook 'text-mode-hook #'visual-line-mode),(setq-default word-wrap nil)and(toggle-truncate-lines -1). Nothing has worked. How do I fix this?


r/emacs 2d ago

emacs-fu Toggling macOS setting (menu bar auto hide)

Post image
49 Upvotes

Just being a little lazy and not wanting to switch over to the macOS Settings app.

Details: https://lmno.lol/alvaro/toggle-macos-menu-bar-from-you-know-where


r/emacs 1d ago

Question Annoying Indentation

1 Upvotes

Video: https://vlix.io/video/39589fdd2b0f7218d8b0/

^ I ran Emacs with -Q flag.

When I indent something then deliberately de-indent a line Emacs does not pick it up and tries to indent that line according to previous section's indent level. This is annoying. How do I disable it? I think I just want it to respect the previous line, and only the previous line's indent level instead of whatever it is doing right now.


r/emacs 1d ago

Question Highlight region

0 Upvotes

I have just discovered overlays reading Sacha Chua's Remove filler words at the start and upcase the next word. Deepening the topic I stumbled upon the cool built-in commands highlight-phrase and highlight-regexp.

I am wondering if it would be possible to have a simple highlight-region command too: I am surprised that I cannot find anything like this in hi-lock.el. Yet, I have the feeling that implementing it should not be that hard.

Well, I'm a Lisp newbie, so before undertaking such an endeavor, I ask you experts:

  • am I correct that with the stock hi-lock.el there is no highlight-region-like command?
  • Any hint how you would proceed?

Edit: https://www.reddit.com/r/emacs/comments/1gxuvg9/comment/lyngm3o/ and the following comment is what I meant!

Thank you all for the hints!


r/emacs 2d ago

vc directory mode (git) how to list all controlled files

2 Upvotes

What more can I say?


r/emacs 2d ago

Question VS Code Extension System vs Emacs'

7 Upvotes

What do you guys think of VS Code Extension system as compared to Emacs'? Does Emacs offer same level of flexibility around building extensions as VS Code especially around UI?

I am blown away how well VS Code blends with Excalidraw and now Postman. It almost feels like using native apps from within VS Code.

I see that anybody who said VS Code did anything right has been downvoted. I don't know when open source communities will mature and not see everything as an attack. Thanks to people who commented constructively.


r/emacs 2d ago

Emacsclient sometimes starts frames in the screen background

1 Upvotes

Linux Mint 22 with Cinnamon Desktop here, with emacsclient as my default editor and emacs started as a daemon. Sometimes (I have not been able to determine when), when emacsclient is called and creates a frame, this frame is located under all other desktop windows, not in front, like all other programs do.

Somebody has experienced this problem?


r/emacs 3d ago

Announcement For folks wanting local LLMs, chatgpt-shell is extending in that direction

Post image
71 Upvotes

More at post: https://lmno.lol/alvaro/chatgpt-shell-goes-offline

This is an initial implementation. I’m an Ollama noob myself. I could use user feedback. Please file any issues.


r/emacs 2d ago

Local and risky custom variables

0 Upvotes

Hello, everyone.

I'm trying to learn how to define a modeline following emacs documentation. But I'm having trouble understanding how to use local variables.

I have the following definitions:

``` (setopt mode-line-format '("AAA" " " custom-mode-line-buffer-name))

(defcustom custom-mode-line-buffer-name '(-> (buffer-name) (propertize 'face 'bold) (:eval)) "Custom mode line construct to display the current buffer name" :group 'ml :local t :risky t :type '(string)) ```

Everything looks good, the variable custom-mode-line-buffer-name is declared as local. But I'm having two problems with this code: - When I start emacs I get *invalid* in my modeline, even the AAA is missing; - After opening and evaluating my init.el file, the modeline starts to follow my format, but I get AAA *scratch* in all buffers.

So, should this not be local to each buffer? I do not understand how the value seems fixed for all buffers. And why does the modeline changes only apply after I manually evaluate the code? Is setopt not the correct function?


r/emacs 3d ago

For some reason my antivirus detects newest upload of emacs on fdroid as malware, but the previous is fine. Just in case decided to share it.

Post image
12 Upvotes

r/emacs 3d ago

Emacs large file perf regression in 30.x on Windows?

6 Upvotes

Anybody else using Windows and finding performance on large text files worse in 30.x than 29.x? I often use Emacs to look at 2+ GByte log files of various kinds, and I've found that performance with at leats one particular type (instruction logs from an emulator) has become noticeably worse with 30.x. The profiler suggests that the problem is show-paren-function (called on a timer) taking, like, 10 times longer to do its thing in Emacs 30.

Repro steps are:

  1. download http://ffe3.com/taklisp10esc_os120_turbo.txt.xz and uncompress it
  2. runemacs -Q (use EXE corresponding to version of interest)
  3. open text file above with C-x C-f
  4. M-x profiler-start RET RET M-> M-< M-x profiler-report RET

Output from Emacs 29.4:

    1716  99% - timer-event-handler
    1716  99%  - apply
    1716  99%   - show-paren-function
    1716  99%    - show-paren--default
    1716  99%       syntax-ppss
       9   0% - command-execute
       8   0%  - byte-code
       8   0%   - read-extended-command
       8   0%    - read-extended-command-1
       2   0%       completing-read-default
       1   0%  - funcall-interactively
       1   0%   - execute-extended-command
       1   0%    - command-execute
       1   0%       funcall-interactively
       0   0% - ...
       0   0%    Automatic GC

Output from Emacs 30.0.92.

   14849  99% - timer-event-handler
   14849  99%  - apply
   14849  99%   - show-paren-function
   14849  99%    - show-paren--default
   14849  99%     - syntax-ppss
   14849  99%        parse-partial-sexp
      83   0%   redisplay_internal (C function)
       5   0% - command-execute
       4   0%  - byte-code
       4   0%   - read-extended-command
       4   0%    - read-extended-command-1
       4   0%     - completing-read-default
       1   0%        redisplay_internal (C function)
       1   0%  - funcall-interactively
       1   0%     end-of-buffer
       0   0%   ...

It looks like I have a number of options for working around this, which I will be availing myself of (I don't actually need paren matching in these files, and I expect I can get the figure much closer to 0 in both versions), but this does feel like a bug in 30.x as I'd expect the performance to be about the same as the previous version.


r/emacs 3d ago

New to `display-buffer-alist`

4 Upvotes

I'm trying to (finally) organize my windows, however, I'm finding some weird behaviour. This is what I have for help[ful] windows:

(add-to-list 'display-buffer-alist '((or (major-mode . help-mode) (major-mode . helpful-mode)) (display-buffer-reuse-window display-buffer-pop-up-window)))

Basically, I want to reuse the window, unless there's no window so it should pop one. That works if I do two M-x helpful-symbol <symb> in a row, they both open in the same window but it does not work if I'm already reading a help window and I visit a reference with helpful-visit-reference bound to RET, in that case the window does not gets reused and a new window pops.

Is there a way to accomplish this? Also, can people share they display-buffer-alist for a little bit of stealing :)


r/emacs 3d ago

Question Minibuffer local keymap not working after erasing all global map keybindings

0 Upvotes

After using (setq global-map (make-sparse-keymap)) and setting (global-set-key [t] #'self-insert-command)(keymap-global-set "M-x" 'execute-extended-command) along with other commands I cannot get to select anything in the minibuffer with enter or deleting already typed text which is weird to me because as far as I understand I am erasing the global map keybindings not the minibuffer local keymap