Emacs

311 readers
3 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
 
 

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

427
 
 

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

428
 
 

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

429
 
 

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 '

430
 
 

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.

431
 
 

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!

432
 
 

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

433
 
 

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.

434
 
 

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.

435
 
 

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.

436
 
 

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"))

437
 
 

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 ?

438
 
 

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

439
 
 

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?

440
 
 

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.

441
 
 

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!

442
 
 

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 !

443
444
 
 

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?

445
 
 

(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.

446
 
 

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.

447
 
 

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)
448
449
 
 

Hi there,

I am a big user of GMail's "Scheduled Send" feature. It allows me to reply at my pace and make sure the thread does not become a ping-pong match and replies won't come back earlier than expected.

How to do that "on my own"? I use notmuch + msmtp (within emacs) to handle most of my email but like half of it I have to manage via Gmail's web interface because of the scheduling needs.

I know about msmtp-queue but it is a all or nothing solution. I would love to be able to schedule my emails, either at Emacs level or SMTP level, with some header or something.

Any ideas?

450
view more: ‹ prev next ›