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
276
 
 

There is a little Org issue that has been bugging me for quite long. When using Org for task management, subheadings are typically used to define tasks, often grouped under one heading that defines a project. For instance:

* Project 1
** TODO Task a
** TODO Task b

* Project 2
** TODO Task c

Org folds blank lines at the end of any subtree into the latest subheading. So, when I start unfolding Project 1, Task b shows as Task b..., i.e. it seems to have some hidden description which is misleading. I always go to see what is under Task b... only to find its empty.

A compromise is to set org-cycle-separator-lines to 1. However, this prevents the user from writing descriptions that are well spaced, as this will introduce unwanted blank lines in the folded view. For example:

* Project 1
** TODO Task a

- [ ] Subtask
- [ ] Subtask

** TODO Task b

The above code shows as:

* Project 1
** TODO Task a...

** TODO Task b

Any better solutions?

277
 
 

When I hit the "enter" key, it just goes to the next line and doesn't evaluate the expression.

I tried searching to see if anyone else had experienced this, but I can't find anything. My bad if this is a simple question, but I just haven't been able to figure it out.

It's inconvenient, because oftentimes, there is no M-x equivalent of an S-expression, so I have no way to do something that requires a call to an Emacs Lisp function.

278
 
 

I recently configured company and lsp-mode and now completion in find-file doesnt work and just shows "[Company mode not enabled]" when I try to tab complete. Any idea whats wrong?

Heres my config:

-*- lexical-binding: t; -*-

;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!


;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets. It is optional.
(setq user-full-name "Kaiser Patrishkoff"
      user-mail-address "kpatrishkoff@gmail.com")

;; Doom exposes five (optional) variables for controlling fonts in Doom:
;;
;; - `doom-font' -- the primary font to use
;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable)
;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for
;;   presentations or streaming.
;; - `doom-unicode-font' -- for unicode glyphs
;; - `doom-serif-font' -- for the `fixed-pitch-serif' face
;;
;; See 'C-h v doom-font' for documentation and more examples of what they
;; accept. For example:
;;
;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light)
;;      doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13))
;;
;; If you or Emacs can't find your font, use 'M-x describe-font' to look them
;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to
;; refresh your font settings. If Emacs still can't find your font, it likely
;; wasn't installed correctly. Font issues are rarely Doom issues!

;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
;;
(setq doom-theme 'doom-molokai)
;; (setq doom-theme 'doom-ayu-mirage)
;; (setq doom-theme 'doom-gruvbox)
;; (setq doom-theme 'doom-solarized-dark)
;; (setq doom-theme 'doom-outrun-electric)

;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)

;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")


(setenv "PATH" (concat (getenv "PATH") ":/usr/texbin"))

(add-to-list 'exec-path "/Library/TeX/texbin/pdflatex")

;; Whenever you reconfigure a package, make sure to wrap your config in an
;; `after!' block, otherwise Doom's defaults may override your settings. E.g.
;;
;;   (after! PACKAGE
;;     (setq x y))
;;
;; The exceptions to this rule:
;;
;;   - Setting file/directory variables (like `org-directory')
;;   - Setting variables which explicitly tell you to set them before their
;;     package is loaded (see 'C-h v VARIABLE' to look up their documentation).
;;   - Setting doom variables (which start with 'doom-' or '+').
;;
;; Here are some additional functions/macros that will help you configure Doom.
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages

;;   `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces,
;; etc).
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
(add-hook 'org-mode-hook 'org-cdlatex-mode)
(add-hook 'org-mode-hook 'org-fragtog-mode)
(add-hook 'rust-mode-hook 'lsp-deferred)
(yas-global-mode)
(add-hook 'after-init-hook 'global-company-mode)

(use-package! org-fragtog)

(after! evil-org :scale 3)

(setq find-file-wildcards t)

(use-package lsp-mode
  :ensure
  :commands lsp
  :custom
  ;; what to use when checking on-save. "check" is default, I prefer clippy
  (lsp-rust-analyzer-cargo-watch-command "clippy")
  (lsp-eldoc-render-all t)
  (lsp-idle-delay 0.6)
  ;; enable / disable the hints as you prefer:
  (lsp-inlay-hint-enable t)
  ;; These are optional configurations. See https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/#lsp-rust-analyzer-display-chaining-hints for a full list
  (lsp-rust-analyzer-display-lifetime-elision-hints-enable t)
  (lsp-rust-analyzer-display-chaining-hints t)
  (lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names t)
  (lsp-rust-analyzer-display-closure-return-type-hints t)
  (lsp-rust-analyzer-display-parameter-hints t)
  (lsp-rust-analyzer-display-reborrow-hints nil)
  :config
  (add-hook 'lsp-mode-hook 'lsp-ui-mode)
  (add-hook 'rust-mode-hook 'lsp-rust-analyzer-inlay-hints-mode))

(use-package lsp-ui
  :ensure
  :commands lsp-ui-mode
  :custom
  (lsp-ui-peek-always-show t)
  (lsp-ui-sideline-show-hover t)
  (lsp-ui-doc-enable nil))

(use-package company
  :ensure
  :custom
  (company--idle-delay 0.3)
  (company-minimum-prefix-length 1)
  :bind
    (:map company-mode-map
     ("". company-indent-or-complete-common)
	))
(company-tng-configure-default)

(use-package yasnippet
  :ensure
  :config
  (yas-reload-all)
  (add-hook 'prog-mode-hook 'yas-minor-mode)
  (add-hook 'text-mode-hook 'yas-minor-mode))

(use-package yasnippet-classic-snippets)

(use-package flycheck :ensure)

(setq lsp-inlay-hint-enable t)

(global-set-key (kbd "") 'company-indent-or-complete-common)
279
 
 

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.

280
 
 

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

281
 
 

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?

282
 
 

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.

283
 
 

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?

284
 
 

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! 🙃

285
 
 

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?

286
 
 

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?

287
 
 

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!

288
 
 

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!

289
 
 

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.

290
 
 
291
 
 

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.

292
1
Why emacs (alien.top)
submitted 1 year ago by PrezirePlayz@alien.top to c/emacs
 
 

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)

293
294
3
Rate my elisp (alien.top)
submitted 1 year ago by ElfOfPi@alien.top to c/emacs
 
 

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!

295
 
 

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!

296
 
 

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?

297
 
 

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

298
 
 

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?

299
 
 

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

300
 
 

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?

view more: ‹ prev next ›