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
276
 
 

I had updated to sonoma earlier today on M1 MBA. Emacs became laggy, scrolling through my config file turned into a choppy mess.
After downgrading back to Ventura, all performance issues were fixed.

How to downgrade (in case anyone needs this in the future)

  1. Create Bootable USB Installer and download older macOS version from app store

  2. Make a time machine backup

  3. Reboot into startup options

  4. Wipe existing drive, install OS from usb

  5. Transfer files from time machine backup.

277
 
 

Hi all, I saw a cool post the other day with a small snippet of code that was asking for reviews. I love the idea and thought I'd drop in my own little Elisp and ask for the same. This isn't a package yet but hoping to make it one. Would love any hints or tips of what's expected of a package as I've never made my own and this would be the first. The idea of the package is to have autosave work on an idle timer and trigger immediate save when navigating away in various ways. I've been dogfooding it and so far works great for my needs. Thanks in advance!!

(add-variable-watcher 'autosave-toggle
                      #'(lambda (_ value _ _)
                          (if value (autosave-setup) (autosave-teardown))))

(defvar autosave-timer nil
  "Timer for triggering an autosave some once idle time as occurred.
Default is 1 seconds")
(defvar autosave-delay-interval 1
  "The amount of time to wait before autosaving after a change has occurred.")
(defvar autosave-exclude-buffer-list
  '("COMMIT_EDITMSG" "treemacs-persist")
  "List of buffers to exclude from autosaving")

(defvar autosave-immediate-save-functions-list
  '(switch-to-buffer other-window windmove-up windmove-down windmove-left windmove-right next-buffer previous-buffer)
  "A list of functions which trigger an immediate save")

(defmacro advice-add-list (advice-list how function)
  "Add list of advice to given function using the how parameter"
  `(dolist (advice ,advice-list)
     (advice-add advice ,how ,function)))
(defmacro advice-remove-list (advice-list function)
  "Remove list of advice from given function using the how parameter"
  `(dolist (advice ,advice-list)
     (advice-remove advice ,function)))

(defmacro add-hooks (hook-list function)
  "Add list of hooks to given function"
  `(dolist (hook ,hook-list)
    (add-hook hook ,function)))
(defmacro remove-hooks (hook-list function)
  "Remove list of hooks from given function"
  `(dolist (hook ,hook-list)
    (remove-hook hook ,function)))

(defun autosave-setup ()
  "Setup autosave hooks and advice"
  (advice-add-list autosave-immediate-save-functions-list :before #'autosave-save)
  (add-hooks autosave-immediate-save-hooks-list #'autosave-save)
  (add-hook 'post-command-hook #'autosave-delay-save))

(defun autosave-teardown ()
  "Teardown autosave hooks and advice"
  (advice-remove-list autosave-immediate-save-functions-list #'autosave-save)
  (remove-hooks autosave-immediate-save-hooks-list #'autosave-save)
  (remove-hook 'post-command-hook #'autosave-delay-save))

(defvar autosave-immediate-save-hooks-list
  '(mouse-leave-buffer-hook focus-out-hook)
  "A list of hooks which trigger an immediate save")

(defun is-savable-buffer-p ()
  "Check if the current buffer is savable. This is determined by the buffer being a
 file buffer, not excluded and is modified"
  (let ((buffer-not-excluded (not (member (buffer-name) autosave-exclude-buffer-list)))
        (is-file-buffer buffer-file-name)
        (is-modified-buffer (buffer-modified-p)))
     (and buffer-not-excluded is-file-buffer is-modified-buffer)))

(defun autosave-delay-save ()
  "Delay the save for a second to prevent spamming autosave"
  (when (is-savable-buffer-p)
    (when autosave-timer (cancel-timer autosave-timer))
    (setq autosave-timer (run-with-timer autosave-delay-interval nil 'autosave-save))))

(defun autosave-save (&rest _args)
  "Save the current buffer if it is savable"
  (when (is-savable-buffer-p)
    (when autosave-timer (cancel-timer autosave-timer))
    (save-buffer)))

(defvar autosave-toggle t "Toggle for turning on autosave")

278
 
 

Suppose that I have a frame with two windows (split vertically). If I now open org-agenda, it takes over the entire frame rather than appearing in one of the windows. Once I close org-agenda I lose the split window configuration. I have figured out how to restore it using winner package, but is it possible to restrict org-agenda to not take the entire frame?

279
 
 

I've been looking for methods to improve Emacs performance especially with my configuration being over >3k. I'm not particularly interested in startup-time since I never close Emacs. Here's what I found so far

(setq package-native-compile                            t
      gcmh-high-cons-threshold                          100000000
      gc-cons-threshold                                 100000000
      scroll-conservatively                             101
      jit-lock-defer-time                               0
      large-file-warning-threshold                      nil)



(add-hook 'after-init-hook #'(lambda () (setq gc-cons-threshold (* 100 1000 1000))))
(defvar gc-timer nil)
(defun salih/maybe-gc ()
  (let ((original gc-cons-threshold))
    (setq gc-cons-threshold 800000)
    (setq gc-cons-threshold original
          gc-timer (run-with-timer 2 nil #'salih/schedule-maybe-gc))))

(defun salih/schedule-maybe-gc ()
  (setq gc-timer (run-with-idle-timer 2 nil #'salih/maybe-gc)))

(salih/schedule-maybe-gc)

I can tell that I've noticed some improvements.

280
 
 

emacs_without_a_keyboard was an interesting read - so how about emacs on chromebooks?

I had a cursory look at the chromebook keyboard and got scared - is it like Mac where the keys have different names but similar functions?

Perhaps there are config changes or packages needed?

Perhaps it's as different as evil vs holy modes?

Or is it basically impossible to use emacs on chromebooks?

281
 
 

I'm looking for a way to copy images to MacOS Photos App. I know this is probably a rather complex operation, but I also know that there are some die-hard Emacs users out there who use Mac every day. 🍎 So I'm curious if this is possible? Is there a package? I can't seem to find one.

I'm just looking for a way to send images via dired directly to MacOS library at the very least. Since I use dirvish to go through photo sets/collections (Color-tagging them with dired-delight), and I find it to be so much faster to do with dired than with a GUI, I'm just hoping that it's possible for emacs to take me "the next step" to moving the marked ones to the photos libraries I have for MacOS. So, any feedback is welcome! thx! 🙃

282
 
 

I'm using emacs 30 (current master) and the available zotxt mode. When I insert a reference, I get access to selecting it, but then I get a

[[zotero://select/items/nil]]

thing imported and a

[error] request--callback: peculiar error: 400

error. Any idea what that could be?

283
 
 

I would like to write something to have emacs listen on dbus for notifications and update the color of a char on the mode line as telega does. Do you have any suggestions on how to do the above?

284
 
 

Hello everyone,

Hope your weekend is off to a great start. I'm starting my journey on Vim and possibly Emacs (although, who am I kidding, seeing some of its capabilities it seems an inevitability). One thing that would accelerate my timeline to jumping into learning Emacs is if it handled a particular use case that is crucial to me.

See, I do a lot of work in Jupyter Notebooks (Python) for school and ML/prototyping in general. One thing I like about notebooks is that if you make a mistake and the program fails, well, your intermediate calculations are still stored in memory and accessible. It's a graceful fail. If you fail through terminal, well, could be the end of what you calculated.

The problem I have with Jupyter Notebooks is that they do not support parallel processing conveniently. I saw that Emacs has some interesting capabilities around notebook support; I believe org mode is what's used.

I was interested in knowing if anyone uses Emacs as a way to get the best of both worlds: a way to run things using multiprocessing, but should things fail, it store the states in memory to rerun it.

I appreciate any/all insight you have!

285
 
 

After having used org-agenda just for my todos and scheduled events, I just found out one can use it to search one's notes too. It works great! With one bad side-effect. I added several org directories using:

(setq org-agenda-text-search-extra-files (directory-files-recursively "~/Writer/" "\\.org$"))

Now, after searching, all the files the agenda had opened to look for my search string have been added to the list of recent files. So (find-file (completing-read "Recent files: " recentf-list)) becomes less useful because it doesn't show the latest opened files on top of the list anymore, but instead a complete list of all my org-files.

Is there a way to prevent agenda search from caching files into recentf-list?

Thank you very much for any help!

286
 
 

Is there a solution for inserting a filename to a buffer (either to a normal buffer, or to the minibuffer) using a recursive fuzzy search, using the vertico + consult + corfu + cape ecosystem? Something like what consult-file does, but instead of opening the selected file, insert the path of it to a buffer.

We have cape-file, but it doesn't fuzzy search in a recursive way.

287
 
 
288
 
 

Ok, let's compile this stuff

C-x-

wait, it was in the C-c keymap. Let's cancel this keybinding by... um... pressing ESC repeatedly?

C-x ESC ESC: executes (repeat-complex-command)

How can one cancel the current key chain in Emacs? I also tried C-x C-g but i get a message C-x C-g is undefined which makes me think that it isn't reserved for this kind of purpose.

289
 
 

Why not just use vscode if you want a more featured experience, and vim/neovim if you want a minimalistic experience?

(not including the fact that Microsoft owns vscode and that some parts are not open source, im aware of that, so no need to mention it)

290
291
 
 

Hi Emacs community,

I'm an elisp noob, and I recently wrote a function to get the references on a wikipedia page. I plan on using it for org-mode/org-roam so I can do research faster (even though there's probably already a package for that sort of thing). Unfortunately, it's probably not as robust as I would like to think it is, as some of the dois/isbns appear to be missing in some wikipedia pages I've tested. Here it is for reference:

(defun get-wikipedia-references (subject)
  "Gets references for a wikipedia article"
  (let ((wikipedia-prefix-url "https://en.wikipedia.org/wiki/"))
    (with-current-buffer
	(url-retrieve-synchronously (concat wikipedia-prefix-url subject))
      (let* ((html-start (progn (goto-char (point-min))
				(re-search-forward "^$")))
	     (dom (libxml-parse-html-region (1+ (point)) (point-max)))
	     (result))
	(dolist (cite-tag (dom-by-tag dom 'cite) result)
	  (let ((cite-class (dom-attr cite-tag 'class)))
	    (cond ((string-search "journal" cite-class)
		   (let ((a-tag (dom-search cite-tag (lambda (tag) (string-prefix-p "https://doi.org" (dom-attr tag 'href))))))
		     (setq result (cons (cons (concat "doi:" (dom-text a-tag))
					      (let* ((cite-texts (dom-texts cite-tag))
						     (title-beg (1+ (string-search "\"" cite-texts)))
						     (title-end (string-search "\"" cite-texts (1+ title-beg))))
						(substring cite-texts title-beg title-end)
						))
					result))))
		  ((string-search "book" cite-class)
		   (let ((a-tag (dom-search cite-tag (lambda (tag) (string-prefix-p "/wiki/Special:BookSources" (dom-attr tag 'href))))))
		     (setq result (cons (cons (concat "isbn:" (dom-text (dom-child-by-tag a-tag 'bdi)))
					      (dom-text (dom-child-by-tag cite-tag 'i)))
					result))))
		  (t
		   (let ((a-tag (assoc 'a cite-tag)))
		     (setq result (cons (cons (dom-attr a-tag 'href) (dom-text a-tag)) result))))
		  ))
	  )))))

(get-wikipedia-references "Graph_traversal")
(("doi:10.1109/SFCS.1979.34" . "Random walks, universal traversal sequences, and the complexity of maze problems")
 ("doi:10.1016/j.tcs.2015.11.017" . "Lower and upper competitive bounds for online directed graph exploration")
 ("doi:10.1016/j.tcs.2020.06.007" . "Online graph exploration on a restricted graph class: Optimal solutions for tadpole graphs")
 ("doi:10.1587/transinf.E92.D.1620" . "The Online Graph Exploration Problem on Restricted Graphs")
 ("doi:10.1016/j.tcs.2021.04.003" . "An improved lower bound for competitive graph exploration")
 ("doi:10.1137/0206041" . "An Analysis of Several Heuristics for the Traveling Salesman Problem"))

And yes, I know that I could probably use a library like s, dash, seq, or cl, but I try to keep my elisp functions free of those kind of things. I would appreciate any criticism from the Emacs community about my elisp!

292
 
 

I came across citar, and I am trying to use citar-org-roam to take notes on academic papers. I must be missing something about usage/configuration. I get "Make sure 'citar-notes-paths' and 'citar-file-note-extensions' are non-nil" when I try to use citar-open-notes. If I set the 'citar-notes-paths' variable, then citar creates normal notes without using the template defined above.

Here's what is in my init.el:

(use-package org-roam
  :custom
  (org-roam-directory "~/RoamNotes")
  (org-roam-completion-everywhere t)
  (org-roam-capture-templates
  '(("d" "default" plain "%?"
     :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
		             "#+title: ${title}\n")
     :unnarrowed t)
    ("n" "literature note" plain "* Heading\n %?"
     :target (file+head "%(expand-file-name (or citar-org-roam-subdir \"\") org-roam-directory)/${citar-citekey}.org"
		             "#+title: ${citar-citekey} (${citar-date}). ${note-title}.\n#+created: %U\n#+last_modified: %U\n\n")
     :unnarrowed t)))
  :bind (("C-c n l" . org-roam-buffer-toggle)
            ("C-c n f" . org-roam-node-find)
            ("C-c n g" . org-roam-graph)
            ("C-c n i" . org-roam-node-insert)
            ("C-c n c" . org-roam-capture)
            ("C-c n j" . org-roam-dailies-capture-today)
        :map org-mode-map
        ("C-M-i" . completion-at-point))
  :config
  (setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
  (org-roam-db-autosync-mode)
  (require 'org-roam-protocol))

(use-package citar
  :custom
  (citar-bibliography '("~/bib/referencess.bib"))
  :hook
  (LaTeX-mode . citar-capf-setup)
  (org-mode . citar-capf-setup))

(use-package citar-org-roam
  :after (citar org-roam)
  :config
  (setq citar-org-roam-note-title-template "${author} - ${title}")
  (setq citar-org-roam-capture-template-key "n")
  (citar-org-roam-mode))

Thanks for any and all suggestions!

293
 
 

Probably better for r/showerthoughts - but is anyone using emacs without a keyboard?

I assume the core audience of emacs is devs and sysadmins (and perhaps academics with org and org roam)

But surely somebody somewhere is doing those jobs / using assistive tech (dragon etc?) to interface with emacs?

294
 
 

when i open an epub book i need to disable evil-mode in order to be able to jump to next chapter when reading

295
 
 

I am trying to replace straight with Elpaca but I have some troubles with loading some of my local packages that are not from Melpa.

The use-case is to load laas a package for latex snippets. I use the following code

(use-package aas
:elpaca nil
:load-path  (lambda () (expand-file-name "custom/" user-emacs-directory))
)

(use-package laas
:elpaca nil
:load-path  (lambda () (expand-file-name "custom/" user-emacs-directory))
:config
(aas-set-snippets 'laas-mode
;; set condition!
:cond #'texmathp ; expand only while in math
"On" "O(n)"
"O1" "O(1)"
;; bind to functions!
"Sum" (lambda () (interactive)
(yas-expand-snippet "\\sum_{$1}^{$2} $0"))
"Span" (lambda () (interactive)
(yas-expand-snippet "\\Span($1)$0"))
"lr(" (lambda () (interactive)
(yas-expand-snippet "\\left($0\\right)"))
"lr[" (lambda () (interactive)
(yas-expand-snippet "\\left[$0\\right]"))
"lr{" (lambda () (interactive)
(yas-expand-snippet "\\left\\{$0\\right\\}"))
)
(laas-mode)
)

Both files `aas.el` and `laas.el` are in my `(lambda () (expand-file-name "custom/" user-emacs-directory))` durectory and with straight these lines of code worked well but when I switched to Elpaca, laas was not loaded anymore. I tried to add :after tex, do not change anything. I tried to add a hook for latex mode and it also do not change, the laas package is not even loaded.

Can someone help me with this please?

296
 
 

(use-package elfeed)

(leader-key "w" elfeed)

Is it possible to combine the two in a simple way? I tried using :general keyword in use-package ensuring that it loads after general, but it still does not work...

297
 
 

I'm facing a really tough issue with colors getting all messed up after switching to wayland. Is there any simple guide to understand how to change fonts/faces colors in emacs?

298
 
 

So my BT keyboard + trackpad is looking worse for wear.

It was cheap and cheerful with a winning form factor. Other KBs came and went, but it survived.

I need a replacement.

It's been used with emacs (DooM) with my tablet and / or phone for a few years, and has a few shortcomings (see yellow sticker).

I now also have a SteamDeck, which is basically an Arch box, and I'd love a BT keyboard with that.

Does anyone have a portable setup they'd like to share?

Also, is there an emacs-y way to lisp my way out of things like:

  • keys being missing (#);
  • ESC being on a function layer?
299
300
 
 

ellama is a tool for interacting with LLMs from Emacs. It now uses llm library as a backend and supports various providers.

view more: ‹ prev next ›