Emacs

314 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
426
 
 

Both split responsibilities based between on what is the "real config" or "helpers" with macros/functions, but the thing is doom-like-style puts it all in one folder(example: /ui/modeline/config /ui/modeline/utils) while other split in two (lisp/lisp-modeline.el, modules/my-mod-modeline.el), and would like to know your opinion about this and what worked for you.

Some context: By now all my settings are all in one init file, and it already passed the 2k lines mark and once something break, everything breaks, so this is needed to avoid future headaches

427
 
 

If you hate key chords and do chordless editing... what do you use for it?

My story:

Evil: I came to Emacs after a long time of using Vim. Everyone told me to just use Evil and be done with it. I tried Devil but I dont know what it is about it that it left me dissatisfied. There was this feeling that I need to learn Emacs way of doing things. Because all documentation or tutorials I get have Emacs keys. Virtually none of them tell how to do same things in Evil. Always felt like an outsider. Jokes like C-x M-c M-butterfly made me feel like I am not in on the joke because I use Evil. I wanted to learn the Emacs way.

Pure Emacs: So I uninstalled Evil and went all in to pure Emacs keys. I learnt them quickly but key chords always felt difficult on my fingers. Then I found God mode and Devil mode. Great thing about both is that I don't have to define custom key-bindings or learn new key-bindings. They both work out of box and if I know Emacs bindings that's all I need to know.

God mode: First I used God mode for one month. Then I used Devil mode for one month. Both are similar but different. Similar that I don't have to learn new keys like Evil or Spacemacs. But difference is huge. God mode is modal. You are either in God mode or you are not. If you are in God mode you cannot insert text. Not a big problem when I am writing code. It feels like Vim if I am writing code. But it is a big problem when I am using ERC or Vterm or any sort of REPL. Like in Vterm if I change to God mode I cant insert commands. I have to disable God mode to type commands. The constant enabling and disabling of God mode in Vterm felt like burden.

That's why I never used set -o vi in Bash. Same problem with set -o vi ... you have to keep changing between insert and command mode to type command and edit commands. In full interactive prompts, modeless editing is best. So always set -o emacs for me in Bash. That is what drew me to emacs but that is a different story.

Another big problem with God mode is that it does not work in minibuffer. It works only very little in search mode. I think only s is supported in search mode. The other search mode commands don't work in God mode. I think this was my biggest problem with God mode. I mean a big nice thing about Emacs is that everything is a buffer and minibuffer is a buffer and all editing commands work in minibuffer. But God mode doesn't work in minibuffer. :(

Devil mode: Then I tried Devil mode for one month. I am liking it. It works fully in minibuffers and search mode. I am using it with its default , as devil key which is like the leader key in Devil mode. It doesn't disrupt my normal text editing. I can keep inserting text like usual but I can also run emacs commands by pressing ,mx. Don't have to disable/enable it everytime. I can always leave it enabled. Devil is also clever that when I typing lists like [10, 20, 30] it understands that I am writing normal text and it lets me write that without disrupting my flow. It multiplexes "insert mode" and "command mode" in a way that just works. I don't know they did it but it just works. And some keys that I feared running before like M-w or M-^ are so easy to do with Devil with ,mw or ,m^. Another one I like is ,m< or ,m> to go to the top and bottom. Navigation feels like Vim with things like ,nfpbnnnffbbb. Its just ,bnpf instead of hjkl.

So this is my journey of God, Devil and Evil and my review. Hope it was useful to some people. I think Devil might be it for me. Going to try it for another few months and report back if I find something new about it.

I also want to know from you if don't do key chords about what package you use and what you like or don't like about them?

P.S. The presence of all these modes make me happy that I did the right decision by switching to Emacs for life. So much choices. There is no way anyone will write packages like this which change the fundamental way to type keys in Vim. Is it even possible to change the basic way of handling key inputs in vim? But in Emacs, you can reimplement all key input handling from ground up to create a Vim within Emacs. Wow.

428
429
 
 

Hi all,

I recently did "something" in an emacs buffer and lost a bunch of text in different places, and I was unable to undo the deletions. I tried to use ediff (I guess I should have used ediff-backup?) to recover the lost text but not being competent I mixed up buffers "A" and "B" and ended up copying the deletions to the backup file and couldn't recover from there .... :-).

Now I am curious if there are recent 'best practices' to

  1. Avoid doing 'something' that causes text to disappear
  2. Have a more robust, for a beginner like me, set of autosave and associated settings.

I found/checked the following sources:

https://www.gnu.org/software/emacs/manual/html_mono/ediff.html#Major-Entry-Points

https://www.reddit.com/r/emacs/comments/5h7k1r/undo_lost_hours_of_work/

https://www.gnu.org/software/emacs/manual/html_node/elisp/Auto_002dSaving.html

https://www.reddit.com/r/emacs/comments/3sqtig/important_block_of_text_disappeared_from_my_notes/

https://www.gnu.org/software/emacs/manual/html_node/emacs/Version-Control.html

However, regarding the manuals, I think I could benefit from some guidance on how to set up the most robust system (I rather have a lot of littering but with a robust ability to recover files vs a no-littering approach). And regarding users that experienced the same issue, the posts and replies are several years old so maybe obsolete with current emacs version (and package ecosystem).

I am looking for some recommendation to either disabling certain key bindings (e.g., linked to commands that can select/delete a lot of text), or perhaps change certain default settings (e.g., like the one for org-mode that prevents deleting text in folded sections). Or anything that works for you :-).

If the answer is outside of emacs, ie use git with some auto-commit script running in the background, I'd be interested in recommendations as well. I use emacs on my personal MacBook Air and on my company Windows laptop. I don't need to share my files with anyone, I just want to be able to recover from stupid user errors on my side :-).

(I backup to external drives as well, but my scenario is more 'OMG I pressed some key chord when I was doing something else and thought another application was focused but it wasn't. Worst part is I typically don't notice immediately, but only after a while, I may have even been adding a lot of text before realizing I somehow lost a whole bunch of other text somewhere else in a file - I think I read about a setting that asked for confirmation before a large amount of text is killed, but I couldn't find it back. And I also make such mistaken on smaller pieces of text, like a TODO heading in org-mode.)

Thank you for help,

Paul

430
 
 

Hi! Seaman Emacs is my attempt at a literate, modular (module-layer), extensible Emacs configuration.

Seaman makes it easy to add new packages or combinations of packages to your config and safely test them out, as well as phasing out unused packages and remove bloat from your config. Lastly, all source code is easily navigable and documented, with a single .org file in charge of running the show.

If you use Emacs 29 it's super easy to try it out with --init-directory !

I'd appreciate any feedback/suggestions/contributions a lot :)

https://github.com/alopezrivera/Seaman-Emacs/

Design choices:

  • Source: seaman.org contains is the source of all modules and layers. All source files are asynchronously tangled when saving. config.org contains the source code of your (in this case my) config. All blocks inside are asynchronously tangled to init.el when saving
  • Package manager: straight.el
  • Key bindings: Emacs + custom

Out of the box:

  • Clean UI
  • Homescreen
  • Easy theme switching (light/dark)
  • "Full pack" Org Mode with org-agenda, org-calendar, org-roam etc.
  • "Full pack" PDF support with pdf-tools (highlighting, etc.)
  • Magit for VC

Example config:

My personal config built with Seaman is here:

https://github.com/alopezrivera/Seaman-Emacs/blob/main/config.org

431
 
 

I want to write my own emacs config, i am a neovim and spacemacs user. I dont want to use an evil mode.

432
 
 

with evil we have the inner or outer object for selecting inside or outside quote with ", `, '

but I rather have everything hapenning in one go, using the q letter for this. (lazyvim sems to have that setup by default which i seems to have got used to it)

It's easy enough to redefine an object like this:

(define-key evil-outer-text-objects-map "q" 'evil-a-double-quote)
(define-key evil-inner-text-objects-map "q" 'evil-inner-double-quote)

which obviously only select the double quotes, anyone would know how to extend this to backquote ` or single quote '

433
 
 

I use Consult, Vertico and orderless in my config. But when I am looking for a file (consult-ls-git) I would like it not to include subpath or the path when filtering the results, or if it's possible to show matches in filename first - so they have more score for the sorting. Is this possible.

/LoginView/SomeFile.swift
/LoginView/LoginView.swift

Right now I would get this when I type "Login", that fine but if it's not possible to exclude non matching files, I would like the LoginView to be the first choice.

434
 
 

Is there a way to store a link/an url to a website in an orgmode attachment? For instance, pressing `C-c C-a` and then adding a linke to a website, which should then open when I do `org-attach-open`. Would be really nice. Thanks!

435
 
 

Trying to minimize usage of both to make my theme cleaner, but struggling to change it everywhere in each font face

Is there any easier solution?

Doom Emacs 28.2

436
 
 

Is there a way I can compile then run my compiled application, if its already running then exit recompile and run.

So current work flow is compile switch to terminal run binary, switch back make changes compile return to terminal Ctrl + C to kill then run again, be nice if I could do all this from inside emacs.

I guess a bash script could be an option but curious if others have this work flow and how it works ?

Currently in a golang workflow but even better if there is a generic solution.

437
 
 

Hi folks,

Does anyone know if there is a plugin for Emacs that offers like a popup where you search recent files.

Right now I use counsel and it works in minibuffer below...but I saw a video where you could have that working like a mid-screen popup and search files.

438
 
 

I just configured eglot for C++ using clangd, and my eldoc buffers include some spurious characters rendered as two highlighted underscores after each symbol ( e.g., "Foo__"): https://i.imgur.com/Snqt9JA.png

If I copy them to another buffer, they turn out to be a backtick followed by two spaces: "` ".

Does anybody know how to get rid of them?

I tried downloading the latest eglot (rather than using the one that comes with Emacs 29) and setting 'eglot-prefer-plaintext' to 't', but this got rid of all syntax highlighting.

439
 
 

I use the same init for both Windows and Linux.

I would like to simplify my file and use variables for some file locations (using a variable in agenda section, etc).

What is the right way to do that in lisp?

Is it as simple as this?

(setq win-file-location '("c:/Users/Username/Desktop/filename.org"))

(setq linux-file-location '("/home/username/Desktop/filename.org"))

440
 
 

Hello to all, As some of you probably did, i jumped on the treesitter train with emacs 29.1.

I replaced my major modes by their ts counterparts, and gave it a try. For the keywords colors, it was mostly fine, and at first I only checked that and was content with it.

Things went a bit sour when I starting writing code, in particular the indent-rules. I have used mainly the following so far :

  • cmake-ts-mode
  • c++-ts-mode
  • yaml-ts-mode

Over the past two weeks there has not been a work day where I did not have to complete or "fix" indentation rules to my liking.

On the one hand it is much easier than before to tweak things, where either there was a customizable variable, either you were screwed. Now you can add rich rules, kind of easily

On the other hand, the out of the box experience was much worse, barely usable indentation especially for the c++ mode which, despites its 4 presets, lacks the many quick toggles from cc-mode.

I do commend maintainers though for their amazing core implementation, the api + utilities make debugging tree sitter rules a breeze.

How has your treesitter Journey been so far ?

441
 
 

Hey friends! I'm using Doom Emacs and have vc-gutter enabled. When I make changes, a single character (for example = pops up on the left side of the line numbers. This has the effect of shifting the line numbers and all content of the buffer to the right. Ideally, I'd just like the column to ALWAYS be present even if there are no changes. I tried modifying multiple variables, but I believe all the fringe ones are for graphical. Does anyone have guidance? Thanks!

Update: git-gutter:hide-gutter is already set to nil and it doesn't seem to preserve that column.

https://preview.redd.it/vqiankgcamtb1.png?width=307&format=png&auto=webp&s=84ebfc7cd6dd92e84a793afe60069af48c9a7d0a

442
 
 

Is there a way to enable automatic formatting and folding of org-links in a widget form? I have a widget form with text fields where I want to be able to insert org links that should nicely folded and highlighted (as if they were in an org-mode buffer).

Has anyone done something similar?

443
 
 

My eglot just stops working properly from time to time. Every once in a while, it'll get "out of sync" from the buffer. i.e. even after I correct the syntax error it reports, it still sends the old code to LSP, and therefore keeps reporting the fixed errors.

`elgot-reconnect` fixes it, but it's really not a solution to call `eglot-reconnect` every 10 minutes.

444
 
 

Hi,

I have read (but not tested it yet) that logseq has a module to browse or search in the Discogs DB, and I thought "pffff.... emacs has it for years already"... but I hardly find anything on this topic.

I have found an old project on github from Mineo regarding Musicbrainzm but I was expecting more.
Is there any reason for this lack of solutions?

I am no developer, I am not complaining, but I am surprised, this is probably the first domain where I can not find a good solution for my needs with emacs (I may also have poorly searched, would it be the case, please show me the path to the truth!!!!)

Any idea why? Thx for your insights!

445
 
 

I am a C++ dev. I am now able to follow up symbols or files using LSP,/projectile/ivy/transient aso... but inside one file, I have difficulties going quickly up function by function, or by if/for statement. Do you know a convenient way to do this ? I am interested in any navigation tips as well ! Thanks for your help !

446
447
 
 

When writing C code in org mode, things , after pressing Enter or Tab, like...

*(p2+1)='e';

end up w/ preceding commas. I've tried w/ emacs -q and I have the same issue. Is there any short term fix for this?

UPDATE

I realize now this is a quoting mechanism to prevent confusion inside an org document, and that this should not be removed. Instead is there a good way to font lock these commas so that they are barely visible?

448
 
 

(caveat: I have only briefly reviewed changelogs and didnt spot anything)

I just fired up magit to merge my dev branch into master, and somehow the keys have changed or are not working. I used to hit "b l" to checkout a local branch (in this case master) where I'd then merge dev into it, push it to github, and then checkout out dev again.

I get this message:-

"transient-setup: Suffix magit-branch..merge/remote is not defined or autoloaded as a command"

Hopefully someone here has recently done the slog and can save this lazy individual some time. What changed? I havent touched my magit setup for literally years.

(magit-checkout from minibuffer works fine).

GNU Emacs 29.1.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo version 1.16.0) of 2023-08-10

straight package manager.

449
 
 

If you would have the power to change any Emacs-default setting, what would that be and why?

What kind of setting do you think would be useful for a lot (or a majority) of Emacs-users?

One of my examples:

(fido-vertical-mode t)

Because seeing a list of candidates as you type and being able to choose from it with meaningful key-bindings is way more convenient and efficient than the tab-completion-system (I think this claim is backed by the way all those external packages work; helm, ivy, vertico). This is especially suited for a default because you can still use the tab-completion-system with it. So nobody needs to change habits.

450
 
 

https://preview.redd.it/3b3y02w548tb1.png?width=571&format=png&auto=webp&s=974ad5d713deaf96eaa6f6011e80841ad2f306bb

The code relevant to the issue on my config is as follows (sorry for my dumb elisp skills, I'm still quite new to the editor). Lots of thanks in advanced and I hope I have provided the necessary snippets of code.

The config of the base org pkg:

(use-package org
  :mode ("\\.txt\\'" . org-mode) ;; Org Mode Everywhere
  :gfhook
  ;; #'org-indent-mode
  #'visual-line-mode
  #'logos-focus-mode
  :general
  (:states 'normal :keymaps 'org-mode-map :prefix ","
           "e" '(org-edit-src-code :which-key "edit org src block")
           "s" '("headings" . consult-org-heading)
           "c" '(:ignore t :which-key "literate calc")
           "cr" '("calc eval line" . literate-calc-eval-line)
           "cb" '("calc eval buffer" . literate-calc-eval-buffer)
           "d" '(:ignore t :which-key "denote")
           "dc" '("open or create note" . denote-open-or-create)
           "dl" '("link or create note" . denote-link-or-create)
           "t" '("tangle file" . org-babel-tangle)
           "i" '(:ignore t :which-key "insert")
           "ih" '("insert heading" . org-insert-heading)
           "il" '("insert link" . org-insert-link))
  (org-src-mode-map
   "C-," '("exit org src editing" . org-edit-src-exit))
  :custom
  (org-return-follows-link t)
  (org-ellipsis " ▾")
  (org-hide-emphasis-markers t)
  (org-pretty-entities t)
  (org-auto-align-tags nil)
  (org-special-ctrl-a/e t)
  (org-catch-invisible-edits 'show-and-error)
  (org-src-preserve-indentation t)
  (org-confirm-babel-evaluate nil)
  (org-startup-with-inline-images t)
  (org-startup-folded t))

The org-modern pkg:

(use-package org-modern
  :config
  (setq org-modern-hide-stars nil
	org-modern-list '((?* . "•")
                          (?+ . "‣")))
  (defun setup/org-correct-src-face ()
    (interactive)
    (dolist (org-src-face '(org-block-begin-line
			    org-block-end-line))
      (set-face-background org-src-face (face-attribute 'mode-line :background)))
    (dolist (org-src-face '(org-block-begin-line
			    org-block-end-line))
      (set-face-attribute org-src-face nil :font oci-variable-pitch-font)))
  (global-org-modern-mode))

(use-package org-modern-indent
  :elpaca '(org-modern-indent :host github :repo "jdtsmith/org-modern-indent")
  :ghook ('org-indent-mode-hook #'org-modern-indent-mode))

(elpaca-wait)

The config of my faces:

(defun setup/org-headings ()
  (interactive)
  (dolist (face '((org-level-1 . 1.2)
		  (org-level-2 . 1.1)
		  (org-level-3 . 1.05)
		  (org-level-4 . 1.0)
		  (org-level-5 . 1.1)
		  (org-level-6 . 1.1)
		  (org-level-7 . 1.1)
		  (org-level-8 . 1.1)
		  (org-document-title . 1.2)))
    (set-face-attribute (car face) nil
			:font oci-heading-font
			:weight 'bold
			:height (cdr face))))

(defface org-checkbox-done-text
  '((t (:strike-through t :inherit 'variable-pitch)))
  "Face for the text part of a checked org-mode checkbox.")

(font-lock-add-keywords
 'org-mode
 `(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)"
    1 'org-checkbox-done-text prepend))
 'append)
view more: ‹ prev next ›