From b693464190d6156b9d390bb20e5479fbcd92d866 Mon Sep 17 00:00:00 2001 From: emacs-reddit-tips-n-tricks-bot Date: Sun, 22 Dec 2024 00:58:55 +0000 Subject: [PATCH] Weekly update from 2024-12-22 --- comments.json | 122 ++++---- out.md | 801 ++++++++++++++++++++++++------------------------ out.org | 709 +++++++++++++++++++++--------------------- out_by_year.md | 641 +++++++++++++++++++------------------- out_by_year.org | 601 ++++++++++++++++++------------------ 5 files changed, 1452 insertions(+), 1422 deletions(-) diff --git a/comments.json b/comments.json index ede0f5e..025b906 100644 --- a/comments.json +++ b/comments.json @@ -1,14 +1,14 @@ { "t1_lui5ao9": { "author": "ImJustPassinBy", - "upvotes": 8, - "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][\ud83d\udd17]] \n*Votes* 8\n\nI've recently discovered [[https://github.com/fuxialexander/org-pdftools][~org-pdftools~]] and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function ~org-store-link~:\n\n\\* mark a passage in the pdf, run ~M-x org-store-link~, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it.\n\\* run ~C-c C-l~ in any org-buffer, and it pastes the link and prompts you for a name.\n\nThe installation is easy, you just need to hook it into ~org-mode~:\n\n#+BEGIN_SRC elisp\n (use-package org-pdftools\n :after (org pdf-tools)\n :hook (org-mode . org-pdftools-setup-link))\n\n#+END_SRC\nThe only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (~C-c C-a l~ to list all highlights, ~D~ to delete).\n\nIt has less features than [[https://github.com/org-noter/org-noter][~org-noter~]], but it is more flexible, which is why it suits my use-case better. Unfortunately, it has ~org-noter~ as a dependency, so you will end up loading it either way.", + "upvotes": 9, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][\ud83d\udd17]] \n*Votes* 9\n\nI've recently discovered [[https://github.com/fuxialexander/org-pdftools][~org-pdftools~]] and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function ~org-store-link~:\n\n\\* mark a passage in the pdf, run ~M-x org-store-link~, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it.\n\\* run ~C-c C-l~ in any org-buffer, and it pastes the link and prompts you for a name.\n\nThe installation is easy, you just need to hook it into ~org-mode~:\n\n#+BEGIN_SRC elisp\n (use-package org-pdftools\n :after (org pdf-tools)\n :hook (org-mode . org-pdftools-setup-link))\n\n#+END_SRC\nThe only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (~C-c C-a l~ to list all highlights, ~D~ to delete).\n\nIt has less features than [[https://github.com/org-noter/org-noter][~org-noter~]], but it is more flexible, which is why it suits my use-case better. Unfortunately, it has ~org-noter~ as a dependency, so you will end up loading it either way.", "created_datetime": "2024-10-30 11:21:28+00:00" }, "t1_lr35bm5": { "author": "SlowMovingTarget", - "upvotes": 35, - "body": "** u/SlowMovingTarget [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5][\ud83d\udd17]] \n*Votes* 35\n\nNothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file:\n\n1. Select the text (visual mode with Evil, or however you do it)\n2. ~M-x write-region~ and give it a file name to write out your selection to the named file. Nice and quick.\n\nIt's in the manual, and a basic little feature, but really handy. https://www.gnu.org/software/emacs/manual/html_node/emacs/Misc-File-Ops.html\n\nI guess the other tip is to read the manual. :)", + "upvotes": 36, + "body": "** u/SlowMovingTarget [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5][\ud83d\udd17]] \n*Votes* 36\n\nNothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file:\n\n1. Select the text (visual mode with Evil, or however you do it)\n2. ~M-x write-region~ and give it a file name to write out your selection to the named file. Nice and quick.\n\nIt's in the manual, and a basic little feature, but really handy. https://www.gnu.org/software/emacs/manual/html_node/emacs/Misc-File-Ops.html\n\nI guess the other tip is to read the manual. :)", "created_datetime": "2024-10-09 13:20:00+00:00" }, "t1_lr5ceqe": { @@ -19,14 +19,14 @@ }, "t1_lpbqo0e": { "author": "ImJustPassinBy", - "upvotes": 13, - "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e][\ud83d\udd17]] \n*Votes* 13\n\nI recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [[https://blog.costan.ro/img/emacs-completion-system/switch-to.png][which moves the information in a central pop-up instead]]. For me, this meant using the packages:\n\n\\* [[https://github.com/tumashu/vertico-posframe][~vertico-posframe~]] - for [[https://github.com/minad/vertico][~vertico~]]\n\\* [[https://github.com/yanghaoxie/which-key-posframe][~which-key-posframe~]] - for [[https://github.com/justbur/emacs-which-key][~which-key~]]\n\\* [[https://github.com/yanghaoxie/transient-posframe][~transient-posframe~]] - for all transient commands, e.g., in [[https://github.com/magit/magit][~magit~]] or in [[https://github.com/kickingvegas/casual-suite][~casual-suite~]]\n\nBut regardless what you are using, chances are there already is a suitable ~*-posframe~ package for it. Installing these packages is easy:\n\n#+BEGIN_SRC elisp\n (use-package vertico-posframe\n :init\n (vertico-posframe-mode))\n (use-package which-key-posframe\n :init\n (which-key-posframe-mode))\n (use-package transient-posframe\n :init\n (transient-posframe-mode))\n#+END_SRC", + "upvotes": 14, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e][\ud83d\udd17]] \n*Votes* 14\n\nI recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [[https://blog.costan.ro/img/emacs-completion-system/switch-to.png][which moves the information in a central pop-up instead]]. For me, this meant using the packages:\n\n\\* [[https://github.com/tumashu/vertico-posframe][~vertico-posframe~]] - for [[https://github.com/minad/vertico][~vertico~]]\n\\* [[https://github.com/yanghaoxie/which-key-posframe][~which-key-posframe~]] - for [[https://github.com/justbur/emacs-which-key][~which-key~]]\n\\* [[https://github.com/yanghaoxie/transient-posframe][~transient-posframe~]] - for all transient commands, e.g., in [[https://github.com/magit/magit][~magit~]] or in [[https://github.com/kickingvegas/casual-suite][~casual-suite~]]\n\nBut regardless what you are using, chances are there already is a suitable ~*-posframe~ package for it. Installing these packages is easy:\n\n#+BEGIN_SRC elisp\n (use-package vertico-posframe\n :init\n (vertico-posframe-mode))\n (use-package which-key-posframe\n :init\n (which-key-posframe-mode))\n (use-package transient-posframe\n :init\n (transient-posframe-mode))\n#+END_SRC", "created_datetime": "2024-09-28 11:36:58+00:00" }, "t1_lnqelw9": { "author": "mlk", - "upvotes": 13, - "body": "** u/mlk [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9][\ud83d\udd17]] \n*Votes* 13\n\nI made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (~org-agenda-overriding-header~) with a starting asterisk, e.g \"* Current Tasks\", \"* Today Agenda*\" etc\n\n\n#+BEGIN_SRC elisp\n (defun my/org-agenda-fold()\n \"fold sections of agenda starting with \\\"* \\\" tab\"\n (interactive)\n (setq-local outline-regexp \"^\\\\* \")\n (setq-local outline-heading-end-regexp \"\\n\")\n (setq-local outline-minor-mode-prefix (kbd \"C-'\"))\n (outline-minor-mode)\n (local-set-key outline-minor-mode-prefix outline-mode-prefix-map)\n (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children)\n (map!\n :after evil-org-agenda\n :map evil-org-agenda-mode-map\n :m \"\" #'outline-toggle-children\n :m \"\" #'org-agenda-goto\n :m \"S-\" #'org-agenda-switch-to\n :m \"C-\" #'org-agenda-recenter))\n \n(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold)\n#+END_SRC", + "upvotes": 11, + "body": "** u/mlk [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9][\ud83d\udd17]] \n*Votes* 11\n\nI made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (~org-agenda-overriding-header~) with a starting asterisk, e.g \"* Current Tasks\", \"* Today Agenda*\" etc\n\n\n#+BEGIN_SRC elisp\n (defun my/org-agenda-fold()\n \"fold sections of agenda starting with \\\"* \\\" tab\"\n (interactive)\n (setq-local outline-regexp \"^\\\\* \")\n (setq-local outline-heading-end-regexp \"\\n\")\n (setq-local outline-minor-mode-prefix (kbd \"C-'\"))\n (outline-minor-mode)\n (local-set-key outline-minor-mode-prefix outline-mode-prefix-map)\n (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children)\n (map!\n :after evil-org-agenda\n :map evil-org-agenda-mode-map\n :m \"\" #'outline-toggle-children\n :m \"\" #'org-agenda-goto\n :m \"S-\" #'org-agenda-switch-to\n :m \"C-\" #'org-agenda-recenter))\n \n(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold)\n#+END_SRC", "created_datetime": "2024-09-18 13:49:47+00:00" }, "t1_ls4kmt1": { @@ -43,8 +43,8 @@ }, "t1_llfyzu6": { "author": "ImJustPassinBy", - "upvotes": 11, - "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][\ud83d\udd17]] \n*Votes* 11\n\nI regularly work with different emacs frames on different monitors, and [[https://github.com/emacsmirror/framemove][~framemove~]] is great for switching between them. It can hook into ~windmove~ (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions:\n\n\\* ~fm-up-frame~: move to the frame over the current frame\n\\* ~fm-down-frame~: move to the frame below the current frame\n\\* ~fm-left-frame~: move to the frame left of the current frame\n\\* ~fm-right-frame~: move to the frame right of the current frame\n\nIt's not on any of the major package repositories, so you have to install it manually. Thanks to [[https://github.com/emacsmirror][~emacsmirror~]], this can for example be done as follows using ~use-package~ and ~straight~ (adjust bindings to your liking):\n\n#+BEGIN_SRC elisp\n (use-package framemove\n :straight (:host github :repo \"emacsmirror/framemove\")\n :init\n (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom\n :bind\n ((\"C-x 5 \" . fm-up-frame)\n (\"C-x 5 \" . fm-down-frame)\n (\"C-x 5 \" . fm-left-frame)\n (\"C-x 5 \" . fm-right-frame)))\n\n#+END_SRC\nedit: The only thing I don't understand is why setting ~framemove-hook-into-windmove~ to ~t~ doesn't work in via ~:config~ or ~:custom~. The package is loaded, ~C-h f~ confirms that ~fm-up-frame~ exists, but ~C-h v~ doesn't know ~framemove-hook-into-windmove~. ~framemove-hook-into-windmove~ exists after I run ~fm-up-frame~, but then it's set to ~nil~ and not ~t~.", + "upvotes": 12, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][\ud83d\udd17]] \n*Votes* 12\n\nI regularly work with different emacs frames on different monitors, and [[https://github.com/emacsmirror/framemove][~framemove~]] is great for switching between them. It can hook into ~windmove~ (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions:\n\n\\* ~fm-up-frame~: move to the frame over the current frame\n\\* ~fm-down-frame~: move to the frame below the current frame\n\\* ~fm-left-frame~: move to the frame left of the current frame\n\\* ~fm-right-frame~: move to the frame right of the current frame\n\nIt's not on any of the major package repositories, so you have to install it manually. Thanks to [[https://github.com/emacsmirror][~emacsmirror~]], this can for example be done as follows using ~use-package~ and ~straight~ (adjust bindings to your liking):\n\n#+BEGIN_SRC elisp\n (use-package framemove\n :straight (:host github :repo \"emacsmirror/framemove\")\n :init\n (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom\n :bind\n ((\"C-x 5 \" . fm-up-frame)\n (\"C-x 5 \" . fm-down-frame)\n (\"C-x 5 \" . fm-left-frame)\n (\"C-x 5 \" . fm-right-frame)))\n\n#+END_SRC\nedit: The only thing I don't understand is why setting ~framemove-hook-into-windmove~ to ~t~ doesn't work in via ~:config~ or ~:custom~. The package is loaded, ~C-h f~ confirms that ~fm-up-frame~ exists, but ~C-h v~ doesn't know ~framemove-hook-into-windmove~. ~framemove-hook-into-windmove~ exists after I run ~fm-up-frame~, but then it's set to ~nil~ and not ~t~.", "created_datetime": "2024-09-04 10:03:14+00:00" }, "t1_lkrhqf7": { @@ -79,8 +79,8 @@ }, "t1_ldsl3vy": { "author": "thetemp_", - "upvotes": 10, - "body": "** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][\ud83d\udd17]] \n*Votes* 10\n\nI recently discovered the [[https://github.com/gonewest818/dimmer.el][Dimmer]] package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that *is* focused. And of course, you can customize how much it dims and exclude certain buffers.\n\nI love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore.", + "upvotes": 11, + "body": "** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][\ud83d\udd17]] \n*Votes* 11\n\nI recently discovered the [[https://github.com/gonewest818/dimmer.el][Dimmer]] package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that *is* focused. And of course, you can customize how much it dims and exclude certain buffers.\n\nI love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore.", "created_datetime": "2024-07-18 16:34:00+00:00" }, "t1_l9cmdp9": { @@ -91,8 +91,8 @@ }, "t1_l8d30q3": { "author": "JDRiverRun", - "upvotes": 8, - "body": "** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][\ud83d\udd17]] \n*Votes* 8\n\nA few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [[https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f][this gist]] for the details.", + "upvotes": 9, + "body": "** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][\ud83d\udd17]] \n*Votes* 9\n\nA few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [[https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f][this gist]] for the details.", "created_datetime": "2024-06-13 01:47:13+00:00" }, "t1_l687lg9": { @@ -115,14 +115,14 @@ }, "t1_l2cv5cx": { "author": "pt-guzzardo", - "upvotes": 8, - "body": "** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][\ud83d\udd17]] \n*Votes* 8\n\n#+BEGIN_SRC elisp\n(defun copy-source-for-reddit ()\n (interactive)\n (let ((contents (buffer-substring (point) (mark))))\n (with-temp-buffer\n (insert contents)\n (mark-whole-buffer)\n (indent-rigidly (point) (mark) 4 t)\n (mark-whole-buffer)\n (kill-ring-save 0 0 t))))\n\n#+END_SRC\nA handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer.", + "upvotes": 9, + "body": "** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][\ud83d\udd17]] \n*Votes* 9\n\n#+BEGIN_SRC elisp\n(defun copy-source-for-reddit ()\n (interactive)\n (let ((contents (buffer-substring (point) (mark))))\n (with-temp-buffer\n (insert contents)\n (mark-whole-buffer)\n (indent-rigidly (point) (mark) 4 t)\n (mark-whole-buffer)\n (kill-ring-save 0 0 t))))\n\n#+END_SRC\nA handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer.", "created_datetime": "2024-05-03 05:14:49+00:00" }, "t1_l11l7he": { "author": "remillard", - "upvotes": 13, - "body": "** u/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][\ud83d\udd17]] \n*Votes* 13\n\nI thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. \n\nWell, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The \"project goto file\" (~C-x p f~) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored.\n\nI suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore.\n\nAnyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was.", + "upvotes": 12, + "body": "** u/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][\ud83d\udd17]] \n*Votes* 12\n\nI thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. \n\nWell, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The \"project goto file\" (~C-x p f~) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored.\n\nI suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore.\n\nAnyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was.", "created_datetime": "2024-04-24 13:46:10+00:00" }, "t1_kywimnf": { @@ -133,26 +133,26 @@ }, "t1_kxur0j8": { "author": "saltwaterflyguy", - "upvotes": 10, - "body": "** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][\ud83d\udd17]] \n*Votes* 10\n\ndescribe-\\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v.\n\nIf you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions.", + "upvotes": 11, + "body": "** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][\ud83d\udd17]] \n*Votes* 11\n\ndescribe-\\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v.\n\nIf you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions.", "created_datetime": "2024-04-03 13:59:07+00:00" }, "t1_kuo1f9y": { "author": "vkazanov", - "upvotes": 17, - "body": "** u/vkazanov [[https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y][\ud83d\udd17]] \n*Votes* 17\n\nA dump of my Emacs-related principles after 18 years of tinkering:\n\n1. Don't try to replicate a static IDE setup, Emacs is fluid. \n2. Emacs Lisp is inevitable for Emacser to make this fluidity possible.\n3. Language-agnostic is better than language-specific. \n4. Embrace display-alist, fast window manipulation, winner-mode. \n5. .emacs.el reset every couple of years to accomodate innovation. \n6. Org-mode/org-roam for all documentation, projects, tips. The agenda is not set in stone. Use queries, filters, tweak, evolve things. \n7. A contextual dwim is always better than many keybindings. \n8. Use completion everywhere on everything (vertico is magic). \n9. Contribute to the core and favourite packages.\n\nI am a beginner though, things might change.", + "upvotes": 18, + "body": "** u/vkazanov [[https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y][\ud83d\udd17]] \n*Votes* 18\n\nA dump of my Emacs-related principles after 18 years of tinkering:\n\n1. Don't try to replicate a static IDE setup, Emacs is fluid. \n2. Emacs Lisp is inevitable for Emacser to make this fluidity possible.\n3. Language-agnostic is better than language-specific. \n4. Embrace display-alist, fast window manipulation, winner-mode. \n5. .emacs.el reset every couple of years to accomodate innovation. \n6. Org-mode/org-roam for all documentation, projects, tips. The agenda is not set in stone. Use queries, filters, tweak, evolve things. \n7. A contextual dwim is always better than many keybindings. \n8. Use completion everywhere on everything (vertico is magic). \n9. Contribute to the core and favourite packages.\n\nI am a beginner though, things might change.", "created_datetime": "2024-03-13 12:33:07+00:00" }, "t1_ktogga6": { "author": "demosthenex", - "upvotes": 9, - "body": "** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][\ud83d\udd17]] \n*Votes* 9\n\nM-x ielm Use the repl while learning elisp coding. I had no idea!", + "upvotes": 8, + "body": "** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][\ud83d\udd17]] \n*Votes* 8\n\nM-x ielm Use the repl while learning elisp coding. I had no idea!", "created_datetime": "2024-03-06 22:30:32+00:00" }, "t1_ksifwh1": { "author": "geza42", - "upvotes": 13, - "body": "** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1][\ud83d\udd17]] \n*Votes* 13\n\nIf you use an LSP server with semantic highlighting, it's worth checking out the value of ~font-lock-maximum-decoration~. For example, I use ~c++-mode~ with ~lsp-mode~ (with clangd), I decreased ~font-lock-maximum-decoration~ to ~2~, and I didn't notice any highlighting difference (because the lost highlighting by ~c++-mode~ gets highlighted by ~lsp-mode~), while ~c++-mode~ font-locking become faster (~c++-mode~ 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone).\n\nI use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~", + "upvotes": 12, + "body": "** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1][\ud83d\udd17]] \n*Votes* 12\n\nIf you use an LSP server with semantic highlighting, it's worth checking out the value of ~font-lock-maximum-decoration~. For example, I use ~c++-mode~ with ~lsp-mode~ (with clangd), I decreased ~font-lock-maximum-decoration~ to ~2~, and I didn't notice any highlighting difference (because the lost highlighting by ~c++-mode~ gets highlighted by ~lsp-mode~), while ~c++-mode~ font-locking become faster (~c++-mode~ 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone).\n\nI use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~", "created_datetime": "2024-02-28 09:17:26+00:00" }, "t1_kphrvz3": { @@ -163,8 +163,8 @@ }, "t1_kpct4cp": { "author": "[deleted]", - "upvotes": 10, - "body": "** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp][\ud83d\udd17]] \n*Votes* 10\n\nMany of you probably know of this, but I found \"indirect buffers\" useful.\n\nWhen I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the \"folding\" and \"narrow\" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow ~C-x n s~ into different headings of the file in different windows.\n\nIndirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that ~C-x 4 c C-x n s~ did what I wanted.", + "upvotes": 9, + "body": "** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp][\ud83d\udd17]] \n*Votes* 9\n\nMany of you probably know of this, but I found \"indirect buffers\" useful.\n\nWhen I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the \"folding\" and \"narrow\" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow ~C-x n s~ into different headings of the file in different windows.\n\nIndirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that ~C-x 4 c C-x n s~ did what I wanted.", "created_datetime": "2024-02-07 17:14:26+00:00" }, "t1_kjcu7vp": { @@ -175,8 +175,8 @@ }, "t1_kibmgv2": { "author": "lesliesrussell", - "upvotes": 9, - "body": "** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][\ud83d\udd17]] \n*Votes* 9\n\n[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]]\n\nDefines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \\~my-movement-transient-map\\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \\~activate-my-movement-map\\~ function is defined to activate this transient map, and it is globally bound to \\~C-f\\~.\n\n​\n\nThis setup allows you to press \\~C-f\\~ followed by one of the specified keys (\\~f\\~, \\~b\\~, \\~c\\~, \\~l\\~, \\~n\\~, \\~p\\~) to perform the corresponding movement operation. The \\~set-transient-map\\~ call with a second argument of \\~t\\~ ensures that the transient map stays active until one of its keys is pressed.\n\n​\n\nThis is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask!\n\nI didn't want to drop code in the thread so i put it in a gist", + "upvotes": 10, + "body": "** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][\ud83d\udd17]] \n*Votes* 10\n\n[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]]\n\nDefines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \\~my-movement-transient-map\\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \\~activate-my-movement-map\\~ function is defined to activate this transient map, and it is globally bound to \\~C-f\\~.\n\n​\n\nThis setup allows you to press \\~C-f\\~ followed by one of the specified keys (\\~f\\~, \\~b\\~, \\~c\\~, \\~l\\~, \\~n\\~, \\~p\\~) to perform the corresponding movement operation. The \\~set-transient-map\\~ call with a second argument of \\~t\\~ ensures that the transient map stays active until one of its keys is pressed.\n\n​\n\nThis is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask!\n\nI didn't want to drop code in the thread so i put it in a gist", "created_datetime": "2024-01-17 19:20:18+00:00" }, "t1_khe4dq6": { @@ -193,8 +193,8 @@ }, "t1_kgce54q": { "author": "camel_case_t", - "upvotes": 11, - "body": "** u/camel_case_t [[https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q][\ud83d\udd17]] \n*Votes* 11\n\nThis is maybe more a macOS tip than an Emacs tip, but it always bothered me that ~C-f~, ~C-b~, etc worked in any text box, but not ~M-f~, etc -- turns out that you can easily change that throughout the OS!\n\nI created this file and now Emacs keybindings work everywhere:\n\n#+BEGIN_SRC elisp\n/* ~/Library/KeyBindings/DefaultKeyBinding.dict */\n{\n /* Additional Emacs bindings */\n \"~f\" = \"moveWordForward:\";\n \"~b\" = \"moveWordBackward:\";\n \"~<\" = \"moveToBeginningOfDocument:\";\n \"~>\" = \"moveToEndOfDocument:\";\n \"~v\" = \"pageUp:\";\n \"~d\" = \"deleteWordForward:\";\n \"~^h\" = \"deleteWordBackward:\";\n \"~\\010\" = \"deleteWordBackward:\"; /* Option-backspace */\n \"~\\177\" = \"deleteWordBackward:\"; /* Option-delete */\n}\n\n#+END_SRC\nYou can read more here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html", + "upvotes": 10, + "body": "** u/camel_case_t [[https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q][\ud83d\udd17]] \n*Votes* 10\n\nThis is maybe more a macOS tip than an Emacs tip, but it always bothered me that ~C-f~, ~C-b~, etc worked in any text box, but not ~M-f~, etc -- turns out that you can easily change that throughout the OS!\n\nI created this file and now Emacs keybindings work everywhere:\n\n#+BEGIN_SRC elisp\n/* ~/Library/KeyBindings/DefaultKeyBinding.dict */\n{\n /* Additional Emacs bindings */\n \"~f\" = \"moveWordForward:\";\n \"~b\" = \"moveWordBackward:\";\n \"~<\" = \"moveToBeginningOfDocument:\";\n \"~>\" = \"moveToEndOfDocument:\";\n \"~v\" = \"pageUp:\";\n \"~d\" = \"deleteWordForward:\";\n \"~^h\" = \"deleteWordBackward:\";\n \"~\\010\" = \"deleteWordBackward:\"; /* Option-backspace */\n \"~\\177\" = \"deleteWordBackward:\"; /* Option-delete */\n}\n\n#+END_SRC\nYou can read more here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html", "created_datetime": "2024-01-04 22:16:24+00:00" }, "t1_ke5xr5j": { @@ -217,8 +217,8 @@ }, "t1_k8dlt4c": { "author": "leothrix", - "upvotes": 10, - "body": "** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][\ud83d\udd17]] \n*Votes* 10\n\nNeed to remove an element from a list when you're tinkering with elisp?\n\nSometimes when I'm adding and removing elements from hooks or variables like ~completion-at-point-functions~ I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just:\n\n#+BEGIN_SRC elisp\nM-x remove-hook\n\n#+END_SRC\nAnd you've got an interactive interface (using ~completing-read~) for removing arbitrary elements from any list-like variable. It's _technically_ for altering hooks, but you can abuse it to fool around with lists, too.", + "upvotes": 9, + "body": "** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][\ud83d\udd17]] \n*Votes* 9\n\nNeed to remove an element from a list when you're tinkering with elisp?\n\nSometimes when I'm adding and removing elements from hooks or variables like ~completion-at-point-functions~ I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just:\n\n#+BEGIN_SRC elisp\nM-x remove-hook\n\n#+END_SRC\nAnd you've got an interactive interface (using ~completing-read~) for removing arbitrary elements from any list-like variable. It's _technically_ for altering hooks, but you can abuse it to fool around with lists, too.", "created_datetime": "2023-11-08 16:51:54+00:00" }, "t1_k8c4mz7": { @@ -253,8 +253,8 @@ }, "t1_jwff8bw": { "author": "PriorOutcome", - "upvotes": 9, - "body": "** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][\ud83d\udd17]] \n*Votes* 9\n\nI've been slowly accumulating cases for \"flexing\" the thing at point as a more general ~capitalize-word~ replacement:\n\n#+BEGIN_SRC elisp\n;; Stolen from the wiki somewhere\n(defun increment-number-at-point ()\n \"Increment the number at point.\"\n (interactive)\n (skip-chars-backward \"0-9\")\n (or (looking-at \"[0-9]+\")\n (error \"No number at point\"))\n (replace-match (number-to-string (1+ (string-to-number (match-string 0))))))\n \n(defun lw-flex ()\n \"Perform smart flexing at point.\n \nE.g. capitalize or decapitalize the next word, increment number at point.\"\n (interactive)\n (let ((case-fold-search nil))\n (call-interactively\n (cond ((looking-at \"[0-9]+\") #'increment-number-at-point)\n ((looking-at \"[[:lower:]]\") #'capitalize-word)\n ((looking-at \"==\") (delete-char 1) (insert \"!\") (forward-char 2))\n ((looking-at \"!=\") (delete-char 1) (insert \"=\") (forward-char 2))\n ((looking-at \"+\") (delete-char 1) (insert \"-\") (forward-char 1))\n ((looking-at \"-\") (delete-char 1) (insert \"+\") (forward-char 1))\n ((looking-at \"<=\") (delete-char 2) (insert \">=\") (forward-char 2))\n ((looking-at \">=\") (delete-char 2) (insert \"<=\") (forward-char 2))\n ((looking-at \"<\") (delete-char 1) (insert \">\") (forward-char 1))\n ((looking-at \">\") (delete-char 1) (insert \"<\") (forward-char 1))\n (t #'downcase-word)))))\n\n#+END_SRC\nI bind it to ~M-c~.", + "upvotes": 10, + "body": "** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][\ud83d\udd17]] \n*Votes* 10\n\nI've been slowly accumulating cases for \"flexing\" the thing at point as a more general ~capitalize-word~ replacement:\n\n#+BEGIN_SRC elisp\n;; Stolen from the wiki somewhere\n(defun increment-number-at-point ()\n \"Increment the number at point.\"\n (interactive)\n (skip-chars-backward \"0-9\")\n (or (looking-at \"[0-9]+\")\n (error \"No number at point\"))\n (replace-match (number-to-string (1+ (string-to-number (match-string 0))))))\n \n(defun lw-flex ()\n \"Perform smart flexing at point.\n \nE.g. capitalize or decapitalize the next word, increment number at point.\"\n (interactive)\n (let ((case-fold-search nil))\n (call-interactively\n (cond ((looking-at \"[0-9]+\") #'increment-number-at-point)\n ((looking-at \"[[:lower:]]\") #'capitalize-word)\n ((looking-at \"==\") (delete-char 1) (insert \"!\") (forward-char 2))\n ((looking-at \"!=\") (delete-char 1) (insert \"=\") (forward-char 2))\n ((looking-at \"+\") (delete-char 1) (insert \"-\") (forward-char 1))\n ((looking-at \"-\") (delete-char 1) (insert \"+\") (forward-char 1))\n ((looking-at \"<=\") (delete-char 2) (insert \">=\") (forward-char 2))\n ((looking-at \">=\") (delete-char 2) (insert \"<=\") (forward-char 2))\n ((looking-at \"<\") (delete-char 1) (insert \">\") (forward-char 1))\n ((looking-at \">\") (delete-char 1) (insert \"<\") (forward-char 1))\n (t #'downcase-word)))))\n\n#+END_SRC\nI bind it to ~M-c~.", "created_datetime": "2023-08-16 13:29:50+00:00" }, "t1_jpwn2ts": { @@ -265,8 +265,8 @@ }, "t1_jl5zu6z": { "author": "leothrix", - "upvotes": 15, - "body": "** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][\ud83d\udd17]] \n*Votes* 15\n\nFor ~use-package~ users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about ~esup~, but a built-in capability that makes it very straightforward to find places to optimize your ~init.el~ for significantly faster start times.\n\nEnable ~use-package-compute-statistics~ right after you load ~use-package~:\n\n#+BEGIN_SRC elisp\n(setq use-package-compute-statistics t)\n\n#+END_SRC\nRestart emacs, and then invoke ~use-package-report~. You'll get a table of the load times for each package that ~use-package~ manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right ~:hook~ keyword.", + "upvotes": 13, + "body": "** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][\ud83d\udd17]] \n*Votes* 13\n\nFor ~use-package~ users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about ~esup~, but a built-in capability that makes it very straightforward to find places to optimize your ~init.el~ for significantly faster start times.\n\nEnable ~use-package-compute-statistics~ right after you load ~use-package~:\n\n#+BEGIN_SRC elisp\n(setq use-package-compute-statistics t)\n\n#+END_SRC\nRestart emacs, and then invoke ~use-package-report~. You'll get a table of the load times for each package that ~use-package~ manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right ~:hook~ keyword.", "created_datetime": "2023-05-22 15:23:11+00:00" }, "t1_jhrzybp": { @@ -277,8 +277,8 @@ }, "t1_jgwlxuw": { "author": "WorldsEndless", - "upvotes": 17, - "body": "** u/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw][\ud83d\udd17]] \n*Votes* 17\n\nOften when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a ~BEGIN_SRC~ block, is ~org-babel-demarcate-block~ ~(C-c C-v d)~.", + "upvotes": 18, + "body": "** u/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw][\ud83d\udd17]] \n*Votes* 18\n\nOften when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a ~BEGIN_SRC~ block, is ~org-babel-demarcate-block~ ~(C-c C-v d)~.", "created_datetime": "2023-04-19 17:32:30+00:00" }, "t1_jg34ody": { @@ -301,14 +301,14 @@ }, "t1_jc9t4tc": { "author": "PriorOutcome", - "upvotes": 15, - "body": "** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc][\ud83d\udd17]] \n*Votes* 15\n\nPlain old ~query-replace~ has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain ~y~/~n~:\n\n~!~: replaces all remaning matches\n\n~u~: undo last replacement\n\n~E~: changes replacement string on the fly\n\nAnd many more you can see using ~?~.", + "upvotes": 14, + "body": "** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc][\ud83d\udd17]] \n*Votes* 14\n\nPlain old ~query-replace~ has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain ~y~/~n~:\n\n~!~: replaces all remaning matches\n\n~u~: undo last replacement\n\n~E~: changes replacement string on the fly\n\nAnd many more you can see using ~?~.", "created_datetime": "2023-03-15 09:20:08+00:00" }, "t1_jca66k0": { "author": "slinchisl", - "upvotes": 10, - "body": "** u/slinchisl [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0][\ud83d\udd17]] \n*Votes* 10\n\nI'm once again reminded of the utility of ~read-key~ for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it.\n\nFor example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as\n\n#+BEGIN_SRC elisp\n(defun slot/insert-time ()\n (interactive)\n (let* ((formats '((?i \"ISO 8601\" \"%Y-%m-%d\")\n (?l \"DDmmmYYYY\" \"%d%b%Y\")\n (?t \"Time\" \"%H:%M\")))\n (key (read-key\n (cl-loop for (key label _) in formats\n concat (format \"[%s] %s \"\n (propertize (single-key-description key) 'face 'bold)\n label)))))\n (->> (alist-get key formats)\n cl-second\n format-time-string\n downcase ; Jan -> jan\n insert)))\n#+END_SRC", + "upvotes": 8, + "body": "** u/slinchisl [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0][\ud83d\udd17]] \n*Votes* 8\n\nI'm once again reminded of the utility of ~read-key~ for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it.\n\nFor example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as\n\n#+BEGIN_SRC elisp\n(defun slot/insert-time ()\n (interactive)\n (let* ((formats '((?i \"ISO 8601\" \"%Y-%m-%d\")\n (?l \"DDmmmYYYY\" \"%d%b%Y\")\n (?t \"Time\" \"%H:%M\")))\n (key (read-key\n (cl-loop for (key label _) in formats\n concat (format \"[%s] %s \"\n (propertize (single-key-description key) 'face 'bold)\n label)))))\n (->> (alist-get key formats)\n cl-second\n format-time-string\n downcase ; Jan -> jan\n insert)))\n#+END_SRC", "created_datetime": "2023-03-15 11:56:11+00:00" }, "t1_jbe06qv": { @@ -1147,8 +1147,8 @@ }, "t1_k2f683f": { "author": "hunajakettu", - "upvotes": 9, - "body": "** u/hunajakettu [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f][\ud83d\udd17]] \n*Votes* 9\n\nIt is the only thing that keeps me sane in a Windows shop.", + "upvotes": 8, + "body": "** u/hunajakettu [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f][\ud83d\udd17]] \n*Votes* 8\n\nIt is the only thing that keeps me sane in a Windows shop.", "created_datetime": "2023-09-27 12:21:05+00:00" }, "t1_jli02ld": { @@ -1243,8 +1243,8 @@ }, "t1_kslwb72": { "author": "LionyxML", - "upvotes": 9, - "body": "** u/LionyxML [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72][\ud83d\udd17]] \n*Votes* 9\n\nA blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. \n[[https://www.rahuljuliato.com/posts/lemacs][https://www.rahuljuliato.com/posts/lemacs]]", + "upvotes": 8, + "body": "** u/LionyxML [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72][\ud83d\udd17]] \n*Votes* 8\n\nA blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. \n[[https://www.rahuljuliato.com/posts/lemacs][https://www.rahuljuliato.com/posts/lemacs]]", "created_datetime": "2024-02-28 22:39:26+00:00" }, "t1_ih3s9fl": { @@ -1273,8 +1273,8 @@ }, "t1_lvojz57": { "author": "ImJustPassinBy", - "upvotes": 19, - "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][\ud83d\udd17]] \n*Votes* 19\n\n~use-package~ has an inbuilt feature that roughly reports the loading times of each package on startup ([[https://github.com/jschaf/esup][~esup~]] most likely does a better job, if you can get it to run; there are [[https://github.com/alexmurray/emacs-snap/issues/71][known issues]] on Emacs snap):\n\n1. put ~(setq use-package-compute-statistics t)~ at the beginning of your ~init.el~\n2. restart Emacs\n3. do ~M-x use-package-report~\n\nWhich package is your biggest time sink and why is it worth it? Mine is [[https://github.com/vedang/pdf-tools][~pdf-tools~]], but to my knowledge there is simply no better alternative for working with pdfs in emacs.", + "upvotes": 18, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][\ud83d\udd17]] \n*Votes* 18\n\n~use-package~ has an inbuilt feature that roughly reports the loading times of each package on startup ([[https://github.com/jschaf/esup][~esup~]] most likely does a better job, if you can get it to run; there are [[https://github.com/alexmurray/emacs-snap/issues/71][known issues]] on Emacs snap):\n\n1. put ~(setq use-package-compute-statistics t)~ at the beginning of your ~init.el~\n2. restart Emacs\n3. do ~M-x use-package-report~\n\nWhich package is your biggest time sink and why is it worth it? Mine is [[https://github.com/vedang/pdf-tools][~pdf-tools~]], but to my knowledge there is simply no better alternative for working with pdfs in emacs.", "created_datetime": "2024-11-06 09:43:57+00:00" }, "t1_ksoij65": { @@ -1387,26 +1387,32 @@ }, "t1_lx7y88i": { "author": "konrad1977", - "upvotes": 9, - "body": "** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][\ud83d\udd17]] \n*Votes* 9\n\nI totally forgot about ~use-package-compute-statistics t~ and (M-x) ~use-package-report~. This helped me optimizing my startup time from around 3 seconds to less than a second.", + "upvotes": 11, + "body": "** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][\ud83d\udd17]] \n*Votes* 11\n\nI totally forgot about ~use-package-compute-statistics t~ and (M-x) ~use-package-report~. This helped me optimizing my startup time from around 3 seconds to less than a second.", "created_datetime": "2024-11-15 05:56:01+00:00" }, "t1_lyc7kx9": { "author": "Nice_Elk_55", - "upvotes": 11, - "body": "** u/Nice_Elk_55 [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9][\ud83d\udd17]] \n*Votes* 11\n\nI used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about ~C-h~. Say you want to use rectangle commands and remember they start with ~C-x r~, but can't remember anything after. Just enter ~C-x r~, followed by ~C-h~. It will list all the keys under that prefix. Seems to work with any prefix key like ~M-s~, ~C-c~, etc.\n\nA related thing is that you can explore the keys for a major/minor mode with ~C-h b~, ~describe-bindings~. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings.", + "upvotes": 12, + "body": "** u/Nice_Elk_55 [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9][\ud83d\udd17]] \n*Votes* 12\n\nI used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about ~C-h~. Say you want to use rectangle commands and remember they start with ~C-x r~, but can't remember anything after. Just enter ~C-x r~, followed by ~C-h~. It will list all the keys under that prefix. Seems to work with any prefix key like ~M-s~, ~C-c~, etc.\n\nA related thing is that you can explore the keys for a major/minor mode with ~C-h b~, ~describe-bindings~. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings.", "created_datetime": "2024-11-22 00:45:46+00:00" }, "t1_lzbam44": { "author": "cidra_", - "upvotes": 11, - "body": "** u/cidra_ [[https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44][\ud83d\udd17]] \n*Votes* 11\n\nTIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([[https://github.com/florommel/custom-css.git][custom-css on GitHub]]) but I also discovered that you can easily tweak it \"in real time\" and without any additional package by invoking the GTK inspector using the following function:\n\n#+BEGIN_SRC elisp\n(x-gtk-debug t)\n\n#+END_SRC\nOne thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the ~border-radius~ attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a ~border-radius~ styling on it. I also applied the ~border-radius~ styling on the main window and on the ~decoration~ component (which gives shadowing to the frame)\n\nhttps://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5\n\n#+BEGIN_SRC elisp\ndecoration {\n border-radius:12px;\n}\n \nwindow{\n border-radius: 12px;\n}\n \nmenubar{\n/* \n For some reason the menu bar \n gets a border radius as well. \n Let's cover it \n\\*/\n background-color: white;\n}\n \ntoolbar {\n border-radius: 12px;\n}\n\n#+END_SRC\nNow I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. \ud83e\udd14", + "upvotes": 10, + "body": "** u/cidra_ [[https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44][\ud83d\udd17]] \n*Votes* 10\n\nTIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([[https://github.com/florommel/custom-css.git][custom-css on GitHub]]) but I also discovered that you can easily tweak it \"in real time\" and without any additional package by invoking the GTK inspector using the following function:\n\n#+BEGIN_SRC elisp\n(x-gtk-debug t)\n\n#+END_SRC\nOne thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the ~border-radius~ attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a ~border-radius~ styling on it. I also applied the ~border-radius~ styling on the main window and on the ~decoration~ component (which gives shadowing to the frame)\n\nhttps://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5\n\n#+BEGIN_SRC elisp\ndecoration {\n border-radius:12px;\n}\n \nwindow{\n border-radius: 12px;\n}\n \nmenubar{\n/* \n For some reason the menu bar \n gets a border radius as well. \n Let's cover it \n\\*/\n background-color: white;\n}\n \ntoolbar {\n border-radius: 12px;\n}\n\n#+END_SRC\nNow I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. \ud83e\udd14", "created_datetime": "2024-11-27 22:08:14+00:00" }, "t1_lyptzyu": { "author": "ImJustPassinBy", - "upvotes": 8, - "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][\ud83d\udd17]] \n*Votes* 8\n\nFor people who need to do a quick calculations from time to time but struggle using ~M-x calc~, try ~M-x quick-calc~. You can enter expressions such as ~2*3.4+5~, and the result will be shown and put into your clipboard.", + "upvotes": 9, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][\ud83d\udd17]] \n*Votes* 9\n\nFor people who need to do a quick calculations from time to time but struggle using ~M-x calc~, try ~M-x quick-calc~. You can enter expressions such as ~2*3.4+5~, and the result will be shown and put into your clipboard.", "created_datetime": "2024-11-24 09:31:46+00:00" + }, + "t1_m2mx3xd": { + "author": "ImJustPassinBy", + "upvotes": 11, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd][\ud83d\udd17]] \n*Votes* 11\n\nI just found out that ~M-x make-frame~ creates the frame on the monitor where the mouse cursor is. So for people who use multiple monitors, one alternative to ~M-x make-frame-on-monitor~ and selecting the monitor is to simply have the mouse on the monitor you want.", + "created_datetime": "2024-12-18 09:49:08+00:00" } } \ No newline at end of file diff --git a/out.md b/out.md index 40d3264..194bf42 100644 --- a/out.md +++ b/out.md @@ -9,7 +9,7 @@ I think monthly would be better, given the modest size of this subreddit. # u/SlowMovingTarget [🔗](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5) -**Votes** 35 +**Votes** 36 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -179,17 +179,30 @@ I discovered \\~org-copy-visible\\~ the other day, when I wanted to send somebod That function (which is bound to C-c C-x v by default) let you copy just the outline for the selected region: very useful! -# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57) +# u/vkazanov [🔗](https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y) -**Votes** 19 +**Votes** 18 -`use-package` has an inbuilt feature that roughly reports the loading times of each package on startup ([`esup`](https://github.com/jschaf/esup) most likely does a better job, if you can get it to run; there are [known issues](https://github.com/alexmurray/emacs-snap/issues/71) on Emacs snap): +A dump of my Emacs-related principles after 18 years of tinkering: -1. put `(setq use-package-compute-statistics t)` at the beginning of your `init.el` -2. restart Emacs -3. do `M-x use-package-report` +1. Don't try to replicate a static IDE setup, Emacs is fluid. +2. Emacs Lisp is inevitable for Emacser to make this fluidity possible. +3. Language-agnostic is better than language-specific. +4. Embrace display-alist, fast window manipulation, winner-mode. +5. .emacs.el reset every couple of years to accomodate innovation. +6. Org-mode/org-roam for all documentation, projects, tips. The agenda is not set in stone. Use queries, filters, tweak, evolve things. +7. A contextual dwim is always better than many keybindings. +8. Use completion everywhere on everything (vertico is magic). +9. Contribute to the core and favourite packages. -Which package is your biggest time sink and why is it worth it? Mine is [`pdf-tools`](https://github.com/vedang/pdf-tools), but to my knowledge there is simply no better alternative for working with pdfs in emacs. +I am a beginner though, things might change. + + +# u/WorldsEndless [🔗](https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw) + +**Votes** 18 + +Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a `BEGIN_SRC` block, is `org-babel-demarcate-block` `(C-c C-v d)`. # u/alvarogonzalezs [🔗](https://www.reddit.com/r/emacs/comments/t3_12jexep/comment/t1_jg34ody) @@ -208,30 +221,17 @@ But this week I discovered `ffap-bindings`. This function replaces some key bind Here's a popular Emacs config I just rediscovered. Some cool stuff here. -# u/vkazanov [🔗](https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y) - -**Votes** 17 - -A dump of my Emacs-related principles after 18 years of tinkering: - -1. Don't try to replicate a static IDE setup, Emacs is fluid. -2. Emacs Lisp is inevitable for Emacser to make this fluidity possible. -3. Language-agnostic is better than language-specific. -4. Embrace display-alist, fast window manipulation, winner-mode. -5. .emacs.el reset every couple of years to accomodate innovation. -6. Org-mode/org-roam for all documentation, projects, tips. The agenda is not set in stone. Use queries, filters, tweak, evolve things. -7. A contextual dwim is always better than many keybindings. -8. Use completion everywhere on everything (vertico is magic). -9. Contribute to the core and favourite packages. - -I am a beginner though, things might change. +# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57) +**Votes** 18 -# u/WorldsEndless [🔗](https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw) +`use-package` has an inbuilt feature that roughly reports the loading times of each package on startup ([`esup`](https://github.com/jschaf/esup) most likely does a better job, if you can get it to run; there are [known issues](https://github.com/alexmurray/emacs-snap/issues/71) on Emacs snap): -**Votes** 17 +1. put `(setq use-package-compute-statistics t)` at the beginning of your `init.el` +2. restart Emacs +3. do `M-x use-package-report` -Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a `BEGIN_SRC` block, is `org-babel-demarcate-block` `(C-c C-v d)`. +Which package is your biggest time sink and why is it worth it? Mine is [`pdf-tools`](https://github.com/vedang/pdf-tools), but to my knowledge there is simply no better alternative for working with pdfs in emacs. # u/sauntcartas [🔗](https://www.reddit.com/r/emacs/comments/t3_vnals8/comment/t1_ie7p6ja) @@ -434,37 +434,6 @@ Pretty simple time saver \\\o/ It would be good to archive the questions and tips put in here. I feel like I always find cool stuff in here, but then it becomes very hard to find it later. -# u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z) - -**Votes** 15 - -For `use-package` users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about `esup`, but a built-in capability that makes it very straightforward to find places to optimize your `init.el` for significantly faster start times. - -Enable `use-package-compute-statistics` right after you load `use-package`: - -```elisp -(setq use-package-compute-statistics t) - -``` - -Restart emacs, and then invoke `use-package-report`. You'll get a table of the load times for each package that `use-package` manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right `:hook` keyword. - - -# u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc) - -**Votes** 15 - -Plain old `query-replace` has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain `y~/~n`: - -`!`: replaces all remaning matches - -`u`: undo last replacement - -`E`: changes replacement string on the fly - -And many more you can see using `?`. - - # u/agumonkey [🔗](https://www.reddit.com/r/emacs/comments/t3_y7wrdn/comment/t1_isze25m) **Votes** 15 @@ -537,6 +506,29 @@ Note that there is also an `isearch-query-replace-regexp` command but you don't Migrated to native compiled emacs branch this week. Some hiccups but everything seems to work out of box, including pdf-tools. Great performance improvement. +# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e) + +**Votes** 14 + +I recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [which moves the information in a central pop-up instead](https://blog.costan.ro/img/emacs-completion-system/switch-to.png). For me, this meant using the packages: + +\\\* [`vertico-posframe`](https://github.com/tumashu/vertico-posframe) - for [`vertico`](https://github.com/minad/vertico) \\\* [`which-key-posframe`](https://github.com/yanghaoxie/which-key-posframe) - for [`which-key`](https://github.com/justbur/emacs-which-key) \\\* [`transient-posframe`](https://github.com/yanghaoxie/transient-posframe) - for all transient commands, e.g., in [`magit`](https://github.com/magit/magit) or in [`casual-suite`](https://github.com/kickingvegas/casual-suite) + +But regardless what you are using, chances are there already is a suitable `*-posframe` package for it. Installing these packages is easy: + +```elisp +(use-package vertico-posframe + :init + (vertico-posframe-mode)) +(use-package which-key-posframe + :init + (which-key-posframe-mode)) +(use-package transient-posframe + :init + (transient-posframe-mode)) +``` + + # u/alvarogonzalezs [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l) **Votes** 14 @@ -555,6 +547,21 @@ From `consult-grep` documentation, command line options can be passed to grep, s I have just discovered this, and it made my day. +# u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc) + +**Votes** 14 + +Plain old `query-replace` has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain `y~/~n`: + +`!`: replaces all remaning matches + +`u`: undo last replacement + +`E`: changes replacement string on the fly + +And many more you can see using `?`. + + # u/com4 [🔗](https://www.reddit.com/r/emacs/comments/t3_xq6rpa/comment/t1_iqb2fci) **Votes** 14 @@ -669,77 +676,20 @@ Let me know what is your first impression, what can be improved and what do you I just discovered the [selected](https://github.com/Kungsgeten/selected.el) package, which is brilliant. It creates a keymap that becomes active any time you have an active region. I have bindings for next-line, previous-line, rectangle-mark-mode, end-of-line, upcase-dwim, exchange-point-and-mark, etc. It makes editing and acting on the active region super easy. Sort of like god-mode or Vim's visual mode. -# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e) +# u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z) **Votes** 13 -I recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [which moves the information in a central pop-up instead](https://blog.costan.ro/img/emacs-completion-system/switch-to.png). For me, this meant using the packages: - -\\\* [`vertico-posframe`](https://github.com/tumashu/vertico-posframe) - for [`vertico`](https://github.com/minad/vertico) \\\* [`which-key-posframe`](https://github.com/yanghaoxie/which-key-posframe) - for [`which-key`](https://github.com/justbur/emacs-which-key) \\\* [`transient-posframe`](https://github.com/yanghaoxie/transient-posframe) - for all transient commands, e.g., in [`magit`](https://github.com/magit/magit) or in [`casual-suite`](https://github.com/kickingvegas/casual-suite) +For `use-package` users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about `esup`, but a built-in capability that makes it very straightforward to find places to optimize your `init.el` for significantly faster start times. -But regardless what you are using, chances are there already is a suitable `*-posframe` package for it. Installing these packages is easy: +Enable `use-package-compute-statistics` right after you load `use-package`: ```elisp -(use-package vertico-posframe - :init - (vertico-posframe-mode)) -(use-package which-key-posframe - :init - (which-key-posframe-mode)) -(use-package transient-posframe - :init - (transient-posframe-mode)) -``` - - -# u/mlk [🔗](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9) - -**Votes** 13 - -I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (`org-agenda-overriding-header`) with a starting asterisk, e.g "\* Current Tasks", "\* Today Agenda\*" etc +(setq use-package-compute-statistics t) -```elisp - (defun my/org-agenda-fold() - "fold sections of agenda starting with \"* \" tab" - (interactive) - (setq-local outline-regexp "^\\* ") - (setq-local outline-heading-end-regexp "\n") - (setq-local outline-minor-mode-prefix (kbd "C-'")) - (outline-minor-mode) - (local-set-key outline-minor-mode-prefix outline-mode-prefix-map) - (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children) - (map! - :after evil-org-agenda - :map evil-org-agenda-mode-map - :m "" #'outline-toggle-children - :m "" #'org-agenda-goto - :m "S-" #'org-agenda-switch-to - :m "C-" #'org-agenda-recenter)) - -(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) ``` - -# u/remillard [🔗](https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he) - -**Votes** 13 - -I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. - -Well, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The "project goto file" (`C-x p f`) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored. - -I suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore. - -Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was. - - -# u/geza42 [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1) - -**Votes** 13 - -If you use an LSP server with semantic highlighting, it's worth checking out the value of `font-lock-maximum-decoration`. For example, I use `c++-mode` with `lsp-mode` (with clangd), I decreased `font-lock-maximum-decoration` to `2`, and I didn't notice any highlighting difference (because the lost highlighting by `c++-mode` gets highlighted by `lsp-mode`), while `c++-mode` font-locking become faster (`c++-mode` 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). - -I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ +Restart emacs, and then invoke `use-package-report`. You'll get a table of the load times for each package that `use-package` manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right `:hook` keyword. # u/geza42 [🔗](https://www.reddit.com/r/emacs/comments/t3_11lqkbo/comment/t1_jbe06qv) @@ -1210,6 +1160,54 @@ Here is how I bind it in `bibtex-mode` (plus my other bindings for good measure) Shells in emacs like `shell-mode` and `eshell` can write multi line input using `comint-accumulate`. Normally bound to `C-c SPC`. +# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) + +**Votes** 12 + +I regularly work with different emacs frames on different monitors, and [`framemove`](https://github.com/emacsmirror/framemove) is great for switching between them. It can hook into `windmove` (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: + +\\\* `fm-up-frame`: move to the frame over the current frame \\\* `fm-down-frame`: move to the frame below the current frame \\\* `fm-left-frame`: move to the frame left of the current frame \\\* `fm-right-frame`: move to the frame right of the current frame + +It's not on any of the major package repositories, so you have to install it manually. Thanks to [`emacsmirror`](https://github.com/emacsmirror), this can for example be done as follows using `use-package` and `straight` (adjust bindings to your liking): + +```elisp +(use-package framemove + :straight (:host github :repo "emacsmirror/framemove") + :init + (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom + :bind + (("C-x 5 " . fm-up-frame) + ("C-x 5 " . fm-down-frame) + ("C-x 5 " . fm-left-frame) + ("C-x 5 " . fm-right-frame))) + +``` + +edit: The only thing I don't understand is why setting `framemove-hook-into-windmove` to `t` doesn't work in via `:config` or `:custom`. The package is loaded, `C-h f` confirms that `fm-up-frame` exists, but `C-h v` doesn't know `framemove-hook-into-windmove`. `framemove-hook-into-windmove` exists after I run `fm-up-frame`, but then it's set to `nil` and not `t`. + + +# u/remillard [🔗](https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he) + +**Votes** 12 + +I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. + +Well, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The "project goto file" (`C-x p f`) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored. + +I suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore. + +Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was. + + +# u/geza42 [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1) + +**Votes** 12 + +If you use an LSP server with semantic highlighting, it's worth checking out the value of `font-lock-maximum-decoration`. For example, I use `c++-mode` with `lsp-mode` (with clangd), I decreased `font-lock-maximum-decoration` to `2`, and I didn't notice any highlighting difference (because the lost highlighting by `c++-mode` gets highlighted by `lsp-mode`), while `c++-mode` font-locking become faster (`c++-mode` 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). + +I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ + + # u/ayyess [🔗](https://www.reddit.com/r/emacs/comments/t3_18hc301/comment/t1_kdobd72) **Votes** 12 @@ -1353,30 +1351,50 @@ I tend to have a lot of function that is defined solely to be added to a hook. T ``` -# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) +# u/NiceElk55 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9) -**Votes** 11 +**Votes** 12 -I regularly work with different emacs frames on different monitors, and [`framemove`](https://github.com/emacsmirror/framemove) is great for switching between them. It can hook into `windmove` (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: +I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about `C-h`. Say you want to use rectangle commands and remember they start with `C-x r`, but can't remember anything after. Just enter `C-x r`, followed by `C-h`. It will list all the keys under that prefix. Seems to work with any prefix key like `M-s`, `C-c`, etc. -\\\* `fm-up-frame`: move to the frame over the current frame \\\* `fm-down-frame`: move to the frame below the current frame \\\* `fm-left-frame`: move to the frame left of the current frame \\\* `fm-right-frame`: move to the frame right of the current frame +A related thing is that you can explore the keys for a major/minor mode with `C-h b`, `describe-bindings`. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. -It's not on any of the major package repositories, so you have to install it manually. Thanks to [`emacsmirror`](https://github.com/emacsmirror), this can for example be done as follows using `use-package` and `straight` (adjust bindings to your liking): + +# u/mlk [🔗](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9) + +**Votes** 11 + +I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (`org-agenda-overriding-header`) with a starting asterisk, e.g "\* Current Tasks", "\* Today Agenda\*" etc ```elisp -(use-package framemove - :straight (:host github :repo "emacsmirror/framemove") - :init - (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom - :bind - (("C-x 5 " . fm-up-frame) - ("C-x 5 " . fm-down-frame) - ("C-x 5 " . fm-left-frame) - ("C-x 5 " . fm-right-frame))) - + (defun my/org-agenda-fold() + "fold sections of agenda starting with \"* \" tab" + (interactive) + (setq-local outline-regexp "^\\* ") + (setq-local outline-heading-end-regexp "\n") + (setq-local outline-minor-mode-prefix (kbd "C-'")) + (outline-minor-mode) + (local-set-key outline-minor-mode-prefix outline-mode-prefix-map) + (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children) + (map! + :after evil-org-agenda + :map evil-org-agenda-mode-map + :m "" #'outline-toggle-children + :m "" #'org-agenda-goto + :m "S-" #'org-agenda-switch-to + :m "C-" #'org-agenda-recenter)) + +(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) ``` -edit: The only thing I don't understand is why setting `framemove-hook-into-windmove` to `t` doesn't work in via `:config` or `:custom`. The package is loaded, `C-h f` confirms that `fm-up-frame` exists, but `C-h v` doesn't know `framemove-hook-into-windmove`. `framemove-hook-into-windmove` exists after I run `fm-up-frame`, but then it's set to `nil` and not `t`. + +# u/thetemp\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) + +**Votes** 11 + +I recently discovered the [Dimmer](https://github.com/gonewest818/dimmer.el) package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that **is** focused. And of course, you can customize how much it dims and exclude certain buffers. + +I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. # u/sauntcartas [🔗](https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9) @@ -1406,50 +1424,31 @@ A minor annoyance was that an unwanted link to whatever file location I happened I've just started to use macros. They are amazing. Here are my tips. C-x -( to start recording. C-x-) to stop recording. F4 to run last recorded macro. Always start at the beginning of a line. Always move by words or lines. If you go forward two chars and the next line needs you to go forward three chars, the macro won't work. Always return to the beginning of the line. For added awesome move down to the next line, positioning yourself to use the macro again. -# u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1933co6/comment/t1_khe4dq6) +# u/saltwaterflyguy [🔗](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) **Votes** 11 -I have long had convenience bindings for `org-emphasize` like `super-i` for *italic*, that match system bindings. But I always wanted these to **be smarter**, i.e. do something useful when there is no text selected. Something like intelligently toggling emphasis depending on whether you were already in the right kind of emphasized text, or just emphasize the word at point if not. +describe-\\\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. -[Check out my solution](https://gist.github.com/jdtsmith/55e6a660dd4c0779a600ac81bf9bfc23) (scroll down to see how it acts). Will miss this behavior in other apps! +If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. -# u/algor512 [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kg4ni5d) +# u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1933co6/comment/t1_khe4dq6) **Votes** 11 -Recently I discovered that `C-h C-q` (or `M-x help-quick`) opens a small window showing \\\*Quick Help\\\* buffer with a nice overview of some basic keybindings. It seems that the content of this buffer is configurable via the variable `help-quick-sections`. +I have long had convenience bindings for `org-emphasize` like `super-i` for *italic*, that match system bindings. But I always wanted these to **be smarter**, i.e. do something useful when there is no text selected. Something like intelligently toggling emphasis depending on whether you were already in the right kind of emphasized text, or just emphasize the word at point if not. -I intend to use it as a cheatsheet, reminding me about rare keybindings I always forget; I believe it is easy to make it context-dependent, just by changing the value of `help-quick-sections`. +[Check out my solution](https://gist.github.com/jdtsmith/55e6a660dd4c0779a600ac81bf9bfc23) (scroll down to see how it acts). Will miss this behavior in other apps! -# u/camelcaset [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q) +# u/algor512 [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kg4ni5d) **Votes** 11 -This is maybe more a macOS tip than an Emacs tip, but it always bothered me that `C-f`, `C-b`, etc worked in any text box, but not `M-f`, etc – turns out that you can easily change that throughout the OS! - -I created this file and now Emacs keybindings work everywhere: - -```elisp -/* ~/Library/KeyBindings/DefaultKeyBinding.dict */ -{ - /* Additional Emacs bindings */ - "~f" = "moveWordForward:"; - "~b" = "moveWordBackward:"; - "~<" = "moveToBeginningOfDocument:"; - "~>" = "moveToEndOfDocument:"; - "~v" = "pageUp:"; - "~d" = "deleteWordForward:"; - "~^h" = "deleteWordBackward:"; - "~\010" = "deleteWordBackward:"; /* Option-backspace */ - "~\177" = "deleteWordBackward:"; /* Option-delete */ -} - -``` +Recently I discovered that `C-h C-q` (or `M-x help-quick`) opens a small window showing \\\*Quick Help\\\* buffer with a nice overview of some basic keybindings. It seems that the content of this buffer is configurable via the variable `help-quick-sections`. -You can read more here: +I intend to use it as a cheatsheet, reminding me about rare keybindings I always forget; I believe it is easy to make it context-dependent, just by changing the value of `help-quick-sections`. # u/tryptych [🔗](https://www.reddit.com/r/emacs/comments/t3_w3gx6o/comment/t1_ih6ievs) @@ -1565,55 +1564,18 @@ Edited to add: Sorry folks, this doesn't work like I thought it did. See the com I can't say how often I use `dabbrev-expand` (`M-/`) to complete words. Saves me a ton of time. -# u/NiceElk55 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9) +# u/konrad1977 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i) **Votes** 11 -I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about `C-h`. Say you want to use rectangle commands and remember they start with `C-x r`, but can't remember anything after. Just enter `C-x r`, followed by `C-h`. It will list all the keys under that prefix. Seems to work with any prefix key like `M-s`, `C-c`, etc. +I totally forgot about `use-package-compute-statistics t` and (M-x) `use-package-report`. This helped me optimizing my startup time from around 3 seconds to less than a second. -A related thing is that you can explore the keys for a major/minor mode with `C-h b`, `describe-bindings`. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. - -# u/cidra\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44) +# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd) **Votes** 11 -TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([custom-css on GitHub](https://github.com/florommel/custom-css.git)) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: - -```elisp -(x-gtk-debug t) - -``` - -One thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the `border-radius` attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a `border-radius` styling on it. I also applied the `border-radius` styling on the main window and on the `decoration` component (which gives shadowing to the frame) - -![img](https://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5) - -```elisp -decoration { - border-radius:12px; -} - -window{ - border-radius: 12px; -} - -menubar{ -/* - For some reason the menu bar - gets a border radius as well. - Let's cover it -\*/ - background-color: white; -} - -toolbar { - border-radius: 12px; -} - -``` - -Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 +I just found out that `M-x make-frame` creates the frame on the monitor where the mouse cursor is. So for people who use multiple monitors, one alternative to `M-x make-frame-on-monitor` and selecting the monitor is to simply have the mouse on the monitor you want. # u/fuzzbomb23 [🔗](https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7) @@ -1653,15 +1615,6 @@ Useful when you include some classless css libraries which require you to add at Don't skip `HTML_DOCTYPE` else it will duplicate the attribute because one extra will be added due to `xml:lang` -# u/thetemp\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) - -**Votes** 10 - -I recently discovered the [Dimmer](https://github.com/gonewest818/dimmer.el) package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that **is** focused. And of course, you can customize how much it dims and exclude certain buffers. - -I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. - - # u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) **Votes** 10 @@ -1673,15 +1626,6 @@ Not from me, but I just wanted to share /u/arthurno1 one-line tip to get `which- I assume the same trick applies to other mode-maps as well. -# u/saltwaterflyguy [🔗](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) - -**Votes** 10 - -describe-\\\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. - -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. - - # u/bopboa [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3) **Votes** 10 @@ -1695,17 +1639,6 @@ This is how to have a beacon without installing any packages. ``` -# u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp) - -**Votes** 10 - -Many of you probably know of this, but I found "indirect buffers" useful. - -When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow `C-x n s` into different headings of the file in different windows. - -Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that `C-x 4 c C-x n s` did what I wanted. - - # u/badmaxton [🔗](https://www.reddit.com/r/emacs/comments/t3_19ec8v5/comment/t1_kjcu7vp) **Votes** 10 @@ -1720,55 +1653,99 @@ Just added this to the `:init` section of my embark configuration: This allows super-convenient marking of entries for later `embark-all` using control-tab, instead of having to go first through the `embark` menu. (By default, this key binding is mapped to `file-cache-minibuffer-complete`, which I never use.) -# u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c) +# u/lesliesrussell [🔗](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) **Votes** 10 -Need to remove an element from a list when you're tinkering with elisp? +[transient map for movement](https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf) -Sometimes when I'm adding and removing elements from hooks or variables like `completion-at-point-functions` I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: +Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \\~my-movement-transient-map\\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \\~activate-my-movement-map\\~ function is defined to activate this transient map, and it is globally bound to \\~C-f\\~. -```elisp -M-x remove-hook +​ -``` +This setup allows you to press \\~C-f\\~ followed by one of the specified keys (\\~f\\~, \\~b\\~, \\~c\\~, \\~l\\~, \\~n\\~, \\~p\\~) to perform the corresponding movement operation. The \\~set-transient-map\\~ call with a second argument of \\~t\\~ ensures that the transient map stays active until one of its keys is pressed. -And you've got an interactive interface (using `completing-read`) for removing arbitrary elements from any list-like variable. It's technically for altering hooks, but you can abuse it to fool around with lists, too. +​ +This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! -# u/gusbrs [🔗](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) +I didn't want to drop code in the thread so i put it in a gist + + +# u/camelcaset [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q) **Votes** 10 -I was converting some old `.odt` notes files to `.org` today, and one of the things I wanted to do was to add two spaces after end of sentence periods for proper sentence navigation. So there I was figuring out a general enough regexp for the nth time and, of course, I regretted not having taken note of this the last time. So I decided to do some searching for a good regexp and write it down this time, since this was obviously shared by someone somewhere. And it turns out Emacs has us covered, and I never knew: `repunctuate-sentences`. I have no idea if this is new or has always been there. It is new to me. It uses `query-replace-regexp`, so it's the same experience. And also can be configured for exclusions with `repunctuate-sentences-filter`. Neat! +This is maybe more a macOS tip than an Emacs tip, but it always bothered me that `C-f`, `C-b`, etc worked in any text box, but not `M-f`, etc – turns out that you can easily change that throughout the OS! +I created this file and now Emacs keybindings work everywhere: -# u/slinchisl [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0) +```elisp +/* ~/Library/KeyBindings/DefaultKeyBinding.dict */ +{ + /* Additional Emacs bindings */ + "~f" = "moveWordForward:"; + "~b" = "moveWordBackward:"; + "~<" = "moveToBeginningOfDocument:"; + "~>" = "moveToEndOfDocument:"; + "~v" = "pageUp:"; + "~d" = "deleteWordForward:"; + "~^h" = "deleteWordBackward:"; + "~\010" = "deleteWordBackward:"; /* Option-backspace */ + "~\177" = "deleteWordBackward:"; /* Option-delete */ +} -**Votes** 10 +``` -I'm once again reminded of the utility of `read-key` for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. +You can read more here: -For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as + +# u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw) + +**Votes** 10 + +I've been slowly accumulating cases for "flexing" the thing at point as a more general `capitalize-word` replacement: ```elisp -(defun slot/insert-time () +;; Stolen from the wiki somewhere +(defun increment-number-at-point () + "Increment the number at point." (interactive) - (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") - (?l "DDmmmYYYY" "%d%b%Y") - (?t "Time" "%H:%M"))) - (key (read-key - (cl-loop for (key label _) in formats - concat (format "[%s] %s " - (propertize (single-key-description key) 'face 'bold) - label))))) - (->> (alist-get key formats) - cl-second - format-time-string - downcase ; Jan -> jan - insert))) + (skip-chars-backward "0-9") + (or (looking-at "[0-9]+") + (error "No number at point")) + (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) + +(defun lw-flex () + "Perform smart flexing at point. + +E.g. capitalize or decapitalize the next word, increment number at point." + (interactive) + (let ((case-fold-search nil)) + (call-interactively + (cond ((looking-at "[0-9]+") #'increment-number-at-point) + ((looking-at "[[:lower:]]") #'capitalize-word) + ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) + ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) + ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) + ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) + ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) + ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) + ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) + ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) + (t #'downcase-word))))) + ``` +I bind it to `M-c`. + + +# u/gusbrs [🔗](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) + +**Votes** 10 + +I was converting some old `.odt` notes files to `.org` today, and one of the things I wanted to do was to add two spaces after end of sentence periods for proper sentence navigation. So there I was figuring out a general enough regexp for the nth time and, of course, I regretted not having taken note of this the last time. So I decided to do some searching for a good regexp and write it down this time, since this was obviously shared by someone somewhere. And it turns out Emacs has us covered, and I never knew: `repunctuate-sentences`. I have no idea if this is new or has always been there. It is new to me. It uses `query-replace-regexp`, so it's the same experience. And also can be configured for exclusions with `repunctuate-sentences-filter`. Neat! + # u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mo1bz) @@ -2233,40 +2210,104 @@ For some this will be obvious, but I'm sure there will be at least one person wh > Expand previous word "dynamically". -> Expands to the most recent, preceding word for which this is a prefix. I> ifno suitable preceding word is found, words following point are considered. If still no suitable word is found, then look in the > buffers accepted by the function pointed out by variable +> Expands to the most recent, preceding word for which this is a prefix. I> ifno suitable preceding word is found, words following point are considered. If still no suitable word is found, then look in the > buffers accepted by the function pointed out by variable + +This command is essentially omni-autocomplete. Chances are, the term you're trying to complete is in the buffer you're using or another buffer, and you can hit multiple times to cycle through different completions. I find the expander to be quicker and more deterministic than language autocomplete about 70% of the time. It's especially useful in writing, if you use Emacs for things other than programming, as you can complete proper names and specalized vocabulary quickly. + + +# u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_ikgfxd/comment/t1_g3zeprg) + +**Votes** 10 + +\\\*\*Suggestion for moderators\*\* - Consider putting a note in the weekly announcement for this thread that using 3 backquotes or tildes to make code blocks doesn't work for those of us using old reddit (so the code people post that way is almost unreadable) - and that indenting by 4 spaces is better for compatibility. (Am I the only one who still uses old reddit? :-) ) + + +# u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_heaoiu/comment/t1_fvqq7ck) + +**Votes** 10 + +Undo-tree and kill-ring are two of the best features in Emacs / packages. Change your life today. + +\\\*\* u/b3n [🔗](https://www.reddit.com/r/emacs/comments/t3_gdtqov/comment/t1_fq9186h) \\\*Votes\* 10 + +If you want to switch between two themes, depending on time of day (e.g. a light and dark theme), it's as simple as this: + +```elisp +;; Light +(load-theme 'modus-operandi t t) +(run-at-time "05:00" (* 60 60 24) (lambda () (enable-theme 'modus-operandi)))) + +;; Dark +(load-theme 'modus-vivendi t t) +(run-at-time "21:00" (* 60 60 24) (lambda () (enable-theme 'modus-vivendi)))) + +``` + +This selects the correct theme when starting Emacs and automatically switch when the times come. + + +# u/cidra\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44) + +**Votes** 10 + +TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([custom-css on GitHub](https://github.com/florommel/custom-css.git)) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: + +```elisp +(x-gtk-debug t) + +``` -This command is essentially omni-autocomplete. Chances are, the term you're trying to complete is in the buffer you're using or another buffer, and you can hit multiple times to cycle through different completions. I find the expander to be quicker and more deterministic than language autocomplete about 70% of the time. It's especially useful in writing, if you use Emacs for things other than programming, as you can complete proper names and specalized vocabulary quickly. +One thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the `border-radius` attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a `border-radius` styling on it. I also applied the `border-radius` styling on the main window and on the `decoration` component (which gives shadowing to the frame) +![img](https://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5) -# u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_ikgfxd/comment/t1_g3zeprg) +```elisp +decoration { + border-radius:12px; +} + +window{ + border-radius: 12px; +} + +menubar{ +/* + For some reason the menu bar + gets a border radius as well. + Let's cover it +\*/ + background-color: white; +} + +toolbar { + border-radius: 12px; +} -**Votes** 10 +``` -\\\*\*Suggestion for moderators\*\* - Consider putting a note in the weekly announcement for this thread that using 3 backquotes or tildes to make code blocks doesn't work for those of us using old reddit (so the code people post that way is almost unreadable) - and that indenting by 4 spaces is better for compatibility. (Am I the only one who still uses old reddit? :-) ) +Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 -# u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_heaoiu/comment/t1_fvqq7ck) +# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9) -**Votes** 10 +**Votes** 9 -Undo-tree and kill-ring are two of the best features in Emacs / packages. Change your life today. +I've recently discovered [`org-pdftools`](https://github.com/fuxialexander/org-pdftools) and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function `org-store-link`: -\\\*\* u/b3n [🔗](https://www.reddit.com/r/emacs/comments/t3_gdtqov/comment/t1_fq9186h) \\\*Votes\* 10 +\\\* mark a passage in the pdf, run `M-x org-store-link`, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. \\\* run `C-c C-l` in any org-buffer, and it pastes the link and prompts you for a name. -If you want to switch between two themes, depending on time of day (e.g. a light and dark theme), it's as simple as this: +The installation is easy, you just need to hook it into `org-mode`: ```elisp -;; Light -(load-theme 'modus-operandi t t) -(run-at-time "05:00" (* 60 60 24) (lambda () (enable-theme 'modus-operandi)))) - -;; Dark -(load-theme 'modus-vivendi t t) -(run-at-time "21:00" (* 60 60 24) (lambda () (enable-theme 'modus-vivendi)))) +(use-package org-pdftools + :after (org pdf-tools) + :hook (org-mode . org-pdftools-setup-link)) ``` -This selects the correct theme when starting Emacs and automatically switch when the times come. +The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (`C-c C-a l` to list all highlights, `D` to delete). + +It has less features than [`org-noter`](https://github.com/org-noter/org-noter), but it is more flexible, which is why it suits my use-case better. Unfortunately, it has `org-noter` as a dependency, so you will end up loading it either way. # u/fv\_\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe) @@ -2340,30 +2381,42 @@ return data; [deleted] -# u/demosthenex [🔗](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) +# u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) **Votes** 9 -M-x ielm Use the repl while learning elisp coding. I had no idea! +A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [this gist](https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f) for the details. -# u/lesliesrussell [🔗](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) +# u/pt-guzzardo [🔗](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) **Votes** 9 -[transient map for movement](https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf) +```elisp +(defun copy-source-for-reddit () + (interactive) + (let ((contents (buffer-substring (point) (mark)))) + (with-temp-buffer + (insert contents) + (mark-whole-buffer) + (indent-rigidly (point) (mark) 4 t) + (mark-whole-buffer) + (kill-ring-save 0 0 t)))) -Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \\~my-movement-transient-map\\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \\~activate-my-movement-map\\~ function is defined to activate this transient map, and it is globally bound to \\~C-f\\~. +``` -​ +A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. -This setup allows you to press \\~C-f\\~ followed by one of the specified keys (\\~f\\~, \\~b\\~, \\~c\\~, \\~l\\~, \\~n\\~, \\~p\\~) to perform the corresponding movement operation. The \\~set-transient-map\\~ call with a second argument of \\~t\\~ ensures that the transient map stays active until one of its keys is pressed. -​ +# u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp) -This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! +**Votes** 9 -I didn't want to drop code in the thread so i put it in a gist +Many of you probably know of this, but I found "indirect buffers" useful. + +When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow `C-x n s` into different headings of the file in different windows. + +Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that `C-x 4 c C-x n s` did what I wanted. # u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_18mplfa/comment/t1_ke5xr5j) @@ -2377,62 +2430,38 @@ This makes stack-outputs of debug-buffers much more readable: ``` -# u/Netherus [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7) +# u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c) **Votes** 9 -Just recently found out M-u makes the next word upper case, and the same for M-l for lower case. Maybe nothing fancy, but it's kinda handy for me. +Need to remove an element from a list when you're tinkering with elisp? +Sometimes when I'm adding and removing elements from hooks or variables like `completion-at-point-functions` I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: -# u/frosch03 [🔗](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) +```elisp +M-x remove-hook -**Votes** 9 +``` -Very useful, but I keep forgetting it: +And you've got an interactive interface (using `completing-read`) for removing arbitrary elements from any list-like variable. It's technically for altering hooks, but you can abuse it to fool around with lists, too. -If you have two buffers open in one frame, where one contains just a few lines and otherwise just uses up a lot of space, you can shrink that buffer down just right by using: `C-x -` -And if you want to balance these two buffers again just use `C-x +` +# u/Netherus [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7) +**Votes** 9 -# u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw) +Just recently found out M-u makes the next word upper case, and the same for M-l for lower case. Maybe nothing fancy, but it's kinda handy for me. -**Votes** 9 -I've been slowly accumulating cases for "flexing" the thing at point as a more general `capitalize-word` replacement: +# u/frosch03 [🔗](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) -```elisp -;; Stolen from the wiki somewhere -(defun increment-number-at-point () - "Increment the number at point." - (interactive) - (skip-chars-backward "0-9") - (or (looking-at "[0-9]+") - (error "No number at point")) - (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) - -(defun lw-flex () - "Perform smart flexing at point. - -E.g. capitalize or decapitalize the next word, increment number at point." - (interactive) - (let ((case-fold-search nil)) - (call-interactively - (cond ((looking-at "[0-9]+") #'increment-number-at-point) - ((looking-at "[[:lower:]]") #'capitalize-word) - ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) - ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) - ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) - ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) - ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) - ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) - ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) - ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) - (t #'downcase-word))))) +**Votes** 9 -``` +Very useful, but I keep forgetting it: -I bind it to `M-c`. +If you have two buffers open in one frame, where one contains just a few lines and otherwise just uses up a lot of space, you can shrink that buffer down just right by using: `C-x -` + +And if you want to balance these two buffers again just use `C-x +` # u/sauntcartas [🔗](https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv) @@ -2874,13 +2903,6 @@ tell application "System Events" end tell ``` - -# u/hunajakettu [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f) - -**Votes** 9 - -It is the only thing that keeps me sane in a Windows shop. - \\\*\* u/attentoredaz [🔗](https://www.reddit.com/r/emacs/comments/t3_wqjare/comment/t1_iku77h0) \\\*Votes\* 9 Using [zotra](https://github.com/mpedramfar/zotra), [citar](https://github.com/emacs-citar/citar) and some parts of the Org-cite ecosystem I hacked together a highly experimental but pretty comfortable environment for working with "org-biblatex bibliographies" which are basically like [org-bibtex](http://gewhere.github.io/org-bibtex) but with biblatex entries represented as headings with suitable properties instead of bibtex. I have a function which retrieves a biblatex entry corresponding to an url using zotra and adds a corresponding Org heading with the biblatex fields as properties, and the entry becomes available in Citar as soon as I save the document. Citing these entries then works anywhere, even in the same document with a suitable `#+bibliography: my-org-biblatex-file.org` declaration. Exporting the citations also works with the CSL exporter, no conversion is necessary to a proper biblatex bibliography file (but can be easily done if one needs biblatex-based export). Since the bibliography is an Org document, tagging, agenda commands, column view etc. can all be used with the bibliography entries. In a way it's frightening how much can be achieved building on already existing stuff and with a few lines of Emacs Lisp. @@ -2949,13 +2971,6 @@ See the repo for more examples and to download. The notes of getting it working In case you can't tell I **really** like emacs and it's client server model. -# u/LionyxML [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72) - -**Votes** 9 - -A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. [https://www.rahuljuliato.com/posts/lemacs](https://www.rahuljuliato.com/posts/lemacs) - - # u/emacsomancer [🔗](https://www.reddit.com/r/emacs/comments/t3_gqsz8u/comment/t1_fs5sq09) **Votes** 9 @@ -2971,33 +2986,11 @@ Each person gets a different colour to indicate the part of the file they’re e -# u/konrad1977 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i) +# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu) **Votes** 9 -I totally forgot about `use-package-compute-statistics t` and (M-x) `use-package-report`. This helped me optimizing my startup time from around 3 seconds to less than a second. - - -# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9) - -**Votes** 8 - -I've recently discovered [`org-pdftools`](https://github.com/fuxialexander/org-pdftools) and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function `org-store-link`: - -\\\* mark a passage in the pdf, run `M-x org-store-link`, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. \\\* run `C-c C-l` in any org-buffer, and it pastes the link and prompts you for a name. - -The installation is easy, you just need to hook it into `org-mode`: - -```elisp -(use-package org-pdftools - :after (org pdf-tools) - :hook (org-mode . org-pdftools-setup-link)) - -``` - -The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (`C-c C-a l` to list all highlights, `D` to delete). - -It has less features than [`org-noter`](https://github.com/org-noter/org-noter), but it is more flexible, which is why it suits my use-case better. Unfortunately, it has `org-noter` as a dependency, so you will end up loading it either way. +For people who need to do a quick calculations from time to time but struggle using `M-x calc`, try `M-x quick-calc`. You can enter expressions such as `2*3.4+5`, and the result will be shown and put into your clipboard. # u/meedstrom [🔗](https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro) @@ -3029,13 +3022,6 @@ But now you can just add a space after the opening paren `'(`. This is the new c For users of [rg.el](https://github.com/dajva/rg.el) (emacs interface to ripgrep) there is [rga](https://github.com/phiresky/ripgrep-all) (ripgrep-all) a wrapper around ripgrep that "enables it to search in pdf, docx, sqlite, jpg, movie subtitles (mkv, mp4), etc." You can set the rg executable in the configuration of rg.el like so: `(setq rg-executable (executable-find "rga")` to enable search in multiple document types. -# u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) - -**Votes** 8 - -A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [this gist](https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f) for the details. - - # u/AdjointFunctor [🔗](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx) **Votes** 8 @@ -3043,24 +3029,11 @@ A few people have asked about my code to change cursor color when repeat-mode is I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. -# u/pt-guzzardo [🔗](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) +# u/demosthenex [🔗](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) **Votes** 8 -```elisp -(defun copy-source-for-reddit () - (interactive) - (let ((contents (buffer-substring (point) (mark)))) - (with-temp-buffer - (insert contents) - (mark-whole-buffer) - (indent-rigidly (point) (mark) 4 t) - (mark-whole-buffer) - (kill-ring-save 0 0 t)))) - -``` - -A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. +M-x ielm Use the repl while learning elisp coding. I had no idea! # u/vjgoh [🔗](https://www.reddit.com/r/emacs/comments/t3_18149ql/comment/t1_kahspwz) @@ -3113,6 +3086,33 @@ I'd forgotten about `with-output-to-temp-buffer` which is pretty handy. The `t` (This should be obvious but note that the JWT is not validated or verified. This is intended for debugging only and the JWT should not be trusted.) +# u/slinchisl [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0) + +**Votes** 8 + +I'm once again reminded of the utility of `read-key` for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. + +For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as + +```elisp +(defun slot/insert-time () + (interactive) + (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") + (?l "DDmmmYYYY" "%d%b%Y") + (?t "Time" "%H:%M"))) + (key (read-key + (cl-loop for (key label _) in formats + concat (format "[%s] %s " + (propertize (single-key-description key) 'face 'bold) + label))))) + (->> (alist-get key formats) + cl-second + format-time-string + downcase ; Jan -> jan + insert))) +``` + + # u/w0ntfix [🔗](https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9) **Votes** 8 @@ -3902,6 +3902,13 @@ map super+b send_key ctrl+x @ s b And voila, super works fine in `emacs -nw`! Kitty translates `s-a` into normal terminal-supported control keybindings `C-x @ s a`, which Emacs then translates back into `s-a`. +# u/hunajakettu [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f) + +**Votes** 8 + +It is the only thing that keeps me sane in a Windows shop. + + # u/habamax [🔗](https://www.reddit.com/r/emacs/comments/t3_13qfepf/comment/t1_jli02ld) **Votes** 8 @@ -4197,6 +4204,13 @@ TIL that I can disable \`\`company\`\` for some modes, I needed to do it because works as intended +# u/LionyxML [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72) + +**Votes** 8 + +A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. [https://www.rahuljuliato.com/posts/lemacs](https://www.rahuljuliato.com/posts/lemacs) + + # u/agumonkey [🔗](https://www.reddit.com/r/emacs/comments/t3_w3gx6o/comment/t1_ih3s9fl) **Votes** 8 @@ -4627,10 +4641,3 @@ This function clears a comint-mode buffer in a dwim fashion by preserving the cu (move-to-column col t) (move-beginning-of-line nil)))) ``` - - -# u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu) - -**Votes** 8 - -For people who need to do a quick calculations from time to time but struggle using `M-x calc`, try `M-x quick-calc`. You can enter expressions such as `2*3.4+5`, and the result will be shown and put into your clipboard. diff --git a/out.org b/out.org index aed5087..a603566 100644 --- a/out.org +++ b/out.org @@ -6,7 +6,7 @@ Do you think it might be good to make this a little less frequently refreshed? T I think monthly would be better, given the modest size of this subreddit. ** u/SlowMovingTarget [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5][🔗]] -*Votes* 35 +*Votes* 36 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -151,31 +151,8 @@ I discovered \~org-copy-visible\~ the other day, when I wanted to send somebody That function (which is bound to C-c C-x v by default) let you copy just the outline for the selected region: very useful! -** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][🔗]] -*Votes* 19 - -~use-package~ has an inbuilt feature that roughly reports the loading times of each package on startup ([[https://github.com/jschaf/esup][~esup~]] most likely does a better job, if you can get it to run; there are [[https://github.com/alexmurray/emacs-snap/issues/71][known issues]] on Emacs snap): - -1. put ~(setq use-package-compute-statistics t)~ at the beginning of your ~init.el~ -2. restart Emacs -3. do ~M-x use-package-report~ - -Which package is your biggest time sink and why is it worth it? Mine is [[https://github.com/vedang/pdf-tools][~pdf-tools~]], but to my knowledge there is simply no better alternative for working with pdfs in emacs. - -** u/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_12jexep/comment/t1_jg34ody][🔗]] -*Votes* 18 - -I'm a big user of ~ffap~. I use this function with ~M-x~ each time I want to open a file whose name is under the cursor. - -But this week I discovered ~ffap-bindings~. This function replaces some key bindings to use ~ffap~ when it makes sense. For example, it replaces ~find-file~ with ~find-file-at-point~, so the usual keybindings are enriched at no cost. - -** u/github-alphapapa [[https://www.reddit.com/r/emacs/comments/t3_p6mwx2/comment/t1_h9e6uqq][🔗]] -*Votes* 18 - -Here's a popular Emacs config I just rediscovered. Some cool stuff here. https://github.com/angrybacon/dotemacs - ** u/vkazanov [[https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y][🔗]] -*Votes* 17 +*Votes* 18 A dump of my Emacs-related principles after 18 years of tinkering: @@ -192,10 +169,33 @@ A dump of my Emacs-related principles after 18 years of tinkering: I am a beginner though, things might change. ** u/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw][🔗]] -*Votes* 17 +*Votes* 18 Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a ~BEGIN_SRC~ block, is ~org-babel-demarcate-block~ ~(C-c C-v d)~. +** u/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_12jexep/comment/t1_jg34ody][🔗]] +*Votes* 18 + +I'm a big user of ~ffap~. I use this function with ~M-x~ each time I want to open a file whose name is under the cursor. + +But this week I discovered ~ffap-bindings~. This function replaces some key bindings to use ~ffap~ when it makes sense. For example, it replaces ~find-file~ with ~find-file-at-point~, so the usual keybindings are enriched at no cost. + +** u/github-alphapapa [[https://www.reddit.com/r/emacs/comments/t3_p6mwx2/comment/t1_h9e6uqq][🔗]] +*Votes* 18 + +Here's a popular Emacs config I just rediscovered. Some cool stuff here. https://github.com/angrybacon/dotemacs + +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][🔗]] +*Votes* 18 + +~use-package~ has an inbuilt feature that roughly reports the loading times of each package on startup ([[https://github.com/jschaf/esup][~esup~]] most likely does a better job, if you can get it to run; there are [[https://github.com/alexmurray/emacs-snap/issues/71][known issues]] on Emacs snap): + +1. put ~(setq use-package-compute-statistics t)~ at the beginning of your ~init.el~ +2. restart Emacs +3. do ~M-x use-package-report~ + +Which package is your biggest time sink and why is it worth it? Mine is [[https://github.com/vedang/pdf-tools][~pdf-tools~]], but to my knowledge there is simply no better alternative for working with pdfs in emacs. + ** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_vnals8/comment/t1_ie7p6ja][🔗]] *Votes* 17 @@ -379,32 +379,6 @@ Pretty simple time saver \\o/ It would be good to archive the questions and tips put in here. I feel like I always find cool stuff in here, but then it becomes very hard to find it later. -** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][🔗]] -*Votes* 15 - -For ~use-package~ users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about ~esup~, but a built-in capability that makes it very straightforward to find places to optimize your ~init.el~ for significantly faster start times. - -Enable ~use-package-compute-statistics~ right after you load ~use-package~: - -#+BEGIN_SRC elisp -(setq use-package-compute-statistics t) - -#+END_SRC -Restart emacs, and then invoke ~use-package-report~. You'll get a table of the load times for each package that ~use-package~ manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right ~:hook~ keyword. - -** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc][🔗]] -*Votes* 15 - -Plain old ~query-replace~ has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain ~y~/~n~: - -~!~: replaces all remaning matches - -~u~: undo last replacement - -~E~: changes replacement string on the fly - -And many more you can see using ~?~. - ** u/agumonkey [[https://www.reddit.com/r/emacs/comments/t3_y7wrdn/comment/t1_isze25m][🔗]] *Votes* 15 @@ -469,6 +443,29 @@ Note that there is also an ~isearch-query-replace-regexp~ command but you don't Migrated to native compiled emacs branch this week. Some hiccups but everything seems to work out of box, including pdf-tools. Great performance improvement. +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e][🔗]] +*Votes* 14 + +I recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [[https://blog.costan.ro/img/emacs-completion-system/switch-to.png][which moves the information in a central pop-up instead]]. For me, this meant using the packages: + +\* [[https://github.com/tumashu/vertico-posframe][~vertico-posframe~]] - for [[https://github.com/minad/vertico][~vertico~]] +\* [[https://github.com/yanghaoxie/which-key-posframe][~which-key-posframe~]] - for [[https://github.com/justbur/emacs-which-key][~which-key~]] +\* [[https://github.com/yanghaoxie/transient-posframe][~transient-posframe~]] - for all transient commands, e.g., in [[https://github.com/magit/magit][~magit~]] or in [[https://github.com/kickingvegas/casual-suite][~casual-suite~]] + +But regardless what you are using, chances are there already is a suitable ~*-posframe~ package for it. Installing these packages is easy: + +#+BEGIN_SRC elisp + (use-package vertico-posframe + :init + (vertico-posframe-mode)) + (use-package which-key-posframe + :init + (which-key-posframe-mode)) + (use-package transient-posframe + :init + (transient-posframe-mode)) +#+END_SRC + ** u/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l][🔗]] *Votes* 14 @@ -484,6 +481,19 @@ From ~consult-grep~ documentation, command line options can be passed to grep, s #+END_SRC I have just discovered this, and it made my day. +** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc][🔗]] +*Votes* 14 + +Plain old ~query-replace~ has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain ~y~/~n~: + +~!~: replaces all remaning matches + +~u~: undo last replacement + +~E~: changes replacement string on the fly + +And many more you can see using ~?~. + ** u/com4 [[https://www.reddit.com/r/emacs/comments/t3_xq6rpa/comment/t1_iqb2fci][🔗]] *Votes* 14 @@ -586,73 +596,18 @@ Let me know what is your first impression, what can be improved and what do you I just discovered the [[https://github.com/Kungsgeten/selected.el][selected]] package, which is brilliant. It creates a keymap that becomes active any time you have an active region. I have bindings for next-line, previous-line, rectangle-mark-mode, end-of-line, upcase-dwim, exchange-point-and-mark, etc. It makes editing and acting on the active region super easy. Sort of like god-mode or Vim's visual mode. -** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e][🔗]] +** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][🔗]] *Votes* 13 -I recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [[https://blog.costan.ro/img/emacs-completion-system/switch-to.png][which moves the information in a central pop-up instead]]. For me, this meant using the packages: - -\* [[https://github.com/tumashu/vertico-posframe][~vertico-posframe~]] - for [[https://github.com/minad/vertico][~vertico~]] -\* [[https://github.com/yanghaoxie/which-key-posframe][~which-key-posframe~]] - for [[https://github.com/justbur/emacs-which-key][~which-key~]] -\* [[https://github.com/yanghaoxie/transient-posframe][~transient-posframe~]] - for all transient commands, e.g., in [[https://github.com/magit/magit][~magit~]] or in [[https://github.com/kickingvegas/casual-suite][~casual-suite~]] +For ~use-package~ users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about ~esup~, but a built-in capability that makes it very straightforward to find places to optimize your ~init.el~ for significantly faster start times. -But regardless what you are using, chances are there already is a suitable ~*-posframe~ package for it. Installing these packages is easy: +Enable ~use-package-compute-statistics~ right after you load ~use-package~: #+BEGIN_SRC elisp - (use-package vertico-posframe - :init - (vertico-posframe-mode)) - (use-package which-key-posframe - :init - (which-key-posframe-mode)) - (use-package transient-posframe - :init - (transient-posframe-mode)) -#+END_SRC - -** u/mlk [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9][🔗]] -*Votes* 13 - -I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (~org-agenda-overriding-header~) with a starting asterisk, e.g "* Current Tasks", "* Today Agenda*" etc - +(setq use-package-compute-statistics t) -#+BEGIN_SRC elisp - (defun my/org-agenda-fold() - "fold sections of agenda starting with \"* \" tab" - (interactive) - (setq-local outline-regexp "^\\* ") - (setq-local outline-heading-end-regexp "\n") - (setq-local outline-minor-mode-prefix (kbd "C-'")) - (outline-minor-mode) - (local-set-key outline-minor-mode-prefix outline-mode-prefix-map) - (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children) - (map! - :after evil-org-agenda - :map evil-org-agenda-mode-map - :m "" #'outline-toggle-children - :m "" #'org-agenda-goto - :m "S-" #'org-agenda-switch-to - :m "C-" #'org-agenda-recenter)) - -(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) #+END_SRC - -** u/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][🔗]] -*Votes* 13 - -I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. - -Well, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The "project goto file" (~C-x p f~) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored. - -I suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore. - -Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was. - -** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1][🔗]] -*Votes* 13 - -If you use an LSP server with semantic highlighting, it's worth checking out the value of ~font-lock-maximum-decoration~. For example, I use ~c++-mode~ with ~lsp-mode~ (with clangd), I decreased ~font-lock-maximum-decoration~ to ~2~, and I didn't notice any highlighting difference (because the lost highlighting by ~c++-mode~ gets highlighted by ~lsp-mode~), while ~c++-mode~ font-locking become faster (~c++-mode~ 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). - -I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ +Restart emacs, and then invoke ~use-package-report~. You'll get a table of the load times for each package that ~use-package~ manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right ~:hook~ keyword. ** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_11lqkbo/comment/t1_jbe06qv][🔗]] *Votes* 13 @@ -1096,6 +1051,50 @@ Here is how I bind it in ~bibtex-mode~ (plus my other bindings for good measure) Shells in emacs like ~shell-mode~ and ~eshell~ can write multi line input using ~comint-accumulate~. Normally bound to ~C-c SPC~. +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][🔗]] +*Votes* 12 + +I regularly work with different emacs frames on different monitors, and [[https://github.com/emacsmirror/framemove][~framemove~]] is great for switching between them. It can hook into ~windmove~ (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: + +\* ~fm-up-frame~: move to the frame over the current frame +\* ~fm-down-frame~: move to the frame below the current frame +\* ~fm-left-frame~: move to the frame left of the current frame +\* ~fm-right-frame~: move to the frame right of the current frame + +It's not on any of the major package repositories, so you have to install it manually. Thanks to [[https://github.com/emacsmirror][~emacsmirror~]], this can for example be done as follows using ~use-package~ and ~straight~ (adjust bindings to your liking): + +#+BEGIN_SRC elisp + (use-package framemove + :straight (:host github :repo "emacsmirror/framemove") + :init + (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom + :bind + (("C-x 5 " . fm-up-frame) + ("C-x 5 " . fm-down-frame) + ("C-x 5 " . fm-left-frame) + ("C-x 5 " . fm-right-frame))) + +#+END_SRC +edit: The only thing I don't understand is why setting ~framemove-hook-into-windmove~ to ~t~ doesn't work in via ~:config~ or ~:custom~. The package is loaded, ~C-h f~ confirms that ~fm-up-frame~ exists, but ~C-h v~ doesn't know ~framemove-hook-into-windmove~. ~framemove-hook-into-windmove~ exists after I run ~fm-up-frame~, but then it's set to ~nil~ and not ~t~. + +** u/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][🔗]] +*Votes* 12 + +I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. + +Well, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The "project goto file" (~C-x p f~) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored. + +I suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore. + +Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was. + +** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1][🔗]] +*Votes* 12 + +If you use an LSP server with semantic highlighting, it's worth checking out the value of ~font-lock-maximum-decoration~. For example, I use ~c++-mode~ with ~lsp-mode~ (with clangd), I decreased ~font-lock-maximum-decoration~ to ~2~, and I didn't notice any highlighting difference (because the lost highlighting by ~c++-mode~ gets highlighted by ~lsp-mode~), while ~c++-mode~ font-locking become faster (~c++-mode~ 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). + +I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ + ** u/ayy_ess [[https://www.reddit.com/r/emacs/comments/t3_18hc301/comment/t1_kdobd72][🔗]] *Votes* 12 @@ -1225,31 +1224,46 @@ I tend to have a lot of function that is defined solely to be added to a hook. T ;; (add-hook 'kill-emacs-query-functions #'ask-about-scratch-buffer) #+END_SRC -** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][🔗]] -*Votes* 11 +** u/Nice_Elk_55 [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9][🔗]] +*Votes* 12 -I regularly work with different emacs frames on different monitors, and [[https://github.com/emacsmirror/framemove][~framemove~]] is great for switching between them. It can hook into ~windmove~ (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: +I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about ~C-h~. Say you want to use rectangle commands and remember they start with ~C-x r~, but can't remember anything after. Just enter ~C-x r~, followed by ~C-h~. It will list all the keys under that prefix. Seems to work with any prefix key like ~M-s~, ~C-c~, etc. -\* ~fm-up-frame~: move to the frame over the current frame -\* ~fm-down-frame~: move to the frame below the current frame -\* ~fm-left-frame~: move to the frame left of the current frame -\* ~fm-right-frame~: move to the frame right of the current frame +A related thing is that you can explore the keys for a major/minor mode with ~C-h b~, ~describe-bindings~. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. -It's not on any of the major package repositories, so you have to install it manually. Thanks to [[https://github.com/emacsmirror][~emacsmirror~]], this can for example be done as follows using ~use-package~ and ~straight~ (adjust bindings to your liking): +** u/mlk [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9][🔗]] +*Votes* 11 -#+BEGIN_SRC elisp - (use-package framemove - :straight (:host github :repo "emacsmirror/framemove") - :init - (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom - :bind - (("C-x 5 " . fm-up-frame) - ("C-x 5 " . fm-down-frame) - ("C-x 5 " . fm-left-frame) - ("C-x 5 " . fm-right-frame))) +I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (~org-agenda-overriding-header~) with a starting asterisk, e.g "* Current Tasks", "* Today Agenda*" etc + +#+BEGIN_SRC elisp + (defun my/org-agenda-fold() + "fold sections of agenda starting with \"* \" tab" + (interactive) + (setq-local outline-regexp "^\\* ") + (setq-local outline-heading-end-regexp "\n") + (setq-local outline-minor-mode-prefix (kbd "C-'")) + (outline-minor-mode) + (local-set-key outline-minor-mode-prefix outline-mode-prefix-map) + (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children) + (map! + :after evil-org-agenda + :map evil-org-agenda-mode-map + :m "" #'outline-toggle-children + :m "" #'org-agenda-goto + :m "S-" #'org-agenda-switch-to + :m "C-" #'org-agenda-recenter)) + +(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) #+END_SRC -edit: The only thing I don't understand is why setting ~framemove-hook-into-windmove~ to ~t~ doesn't work in via ~:config~ or ~:custom~. The package is loaded, ~C-h f~ confirms that ~fm-up-frame~ exists, but ~C-h v~ doesn't know ~framemove-hook-into-windmove~. ~framemove-hook-into-windmove~ exists after I run ~fm-up-frame~, but then it's set to ~nil~ and not ~t~. + +** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][🔗]] +*Votes* 11 + +I recently discovered the [[https://github.com/gonewest818/dimmer.el][Dimmer]] package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that *is* focused. And of course, you can customize how much it dims and exclude certain buffers. + +I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. ** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][🔗]] *Votes* 11 @@ -1273,6 +1287,13 @@ A minor annoyance was that an unwanted link to whatever file location I happened I've just started to use macros. They are amazing. Here are my tips. C-x -( to start recording. C-x-) to stop recording. F4 to run last recorded macro. Always start at the beginning of a line. Always move by words or lines. If you go forward two chars and the next line needs you to go forward three chars, the macro won't work. Always return to the beginning of the line. For added awesome move down to the next line, positioning yourself to use the macro again. +** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][🔗]] +*Votes* 11 + +describe-\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. + +If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. + ** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1933co6/comment/t1_khe4dq6][🔗]] *Votes* 11 @@ -1287,31 +1308,6 @@ Recently I discovered that ~C-h C-q~ (or ~M-x help-quick~) opens a small window I intend to use it as a cheatsheet, reminding me about rare keybindings I always forget; I believe it is easy to make it context-dependent, just by changing the value of ~help-quick-sections~. -** u/camel_case_t [[https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q][🔗]] -*Votes* 11 - -This is maybe more a macOS tip than an Emacs tip, but it always bothered me that ~C-f~, ~C-b~, etc worked in any text box, but not ~M-f~, etc -- turns out that you can easily change that throughout the OS! - -I created this file and now Emacs keybindings work everywhere: - -#+BEGIN_SRC elisp -/* ~/Library/KeyBindings/DefaultKeyBinding.dict */ -{ - /* Additional Emacs bindings */ - "~f" = "moveWordForward:"; - "~b" = "moveWordBackward:"; - "~<" = "moveToBeginningOfDocument:"; - "~>" = "moveToEndOfDocument:"; - "~v" = "pageUp:"; - "~d" = "deleteWordForward:"; - "~^h" = "deleteWordBackward:"; - "~\010" = "deleteWordBackward:"; /* Option-backspace */ - "~\177" = "deleteWordBackward:"; /* Option-delete */ -} - -#+END_SRC -You can read more here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html - ** u/tryptych [[https://www.reddit.com/r/emacs/comments/t3_w3gx6o/comment/t1_ih6ievs][🔗]] *Votes* 11 @@ -1406,50 +1402,15 @@ Edited to add: Sorry folks, this doesn't work like I thought it did. See the c I can't say how often I use ~dabbrev-expand~ (~M-/~) to complete words. Saves me a ton of time. -** u/Nice_Elk_55 [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9][🔗]] +** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][🔗]] *Votes* 11 -I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about ~C-h~. Say you want to use rectangle commands and remember they start with ~C-x r~, but can't remember anything after. Just enter ~C-x r~, followed by ~C-h~. It will list all the keys under that prefix. Seems to work with any prefix key like ~M-s~, ~C-c~, etc. - -A related thing is that you can explore the keys for a major/minor mode with ~C-h b~, ~describe-bindings~. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. +I totally forgot about ~use-package-compute-statistics t~ and (M-x) ~use-package-report~. This helped me optimizing my startup time from around 3 seconds to less than a second. -** u/cidra_ [[https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44][🔗]] +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd][🔗]] *Votes* 11 -TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([[https://github.com/florommel/custom-css.git][custom-css on GitHub]]) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: - -#+BEGIN_SRC elisp -(x-gtk-debug t) - -#+END_SRC -One thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the ~border-radius~ attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a ~border-radius~ styling on it. I also applied the ~border-radius~ styling on the main window and on the ~decoration~ component (which gives shadowing to the frame) - -https://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5 - -#+BEGIN_SRC elisp -decoration { - border-radius:12px; -} - -window{ - border-radius: 12px; -} - -menubar{ -/* - For some reason the menu bar - gets a border radius as well. - Let's cover it -\*/ - background-color: white; -} - -toolbar { - border-radius: 12px; -} - -#+END_SRC -Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 +I just found out that ~M-x make-frame~ creates the frame on the monitor where the mouse cursor is. So for people who use multiple monitors, one alternative to ~M-x make-frame-on-monitor~ and selecting the monitor is to simply have the mouse on the monitor you want. ** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][🔗]] *Votes* 10 @@ -1482,13 +1443,6 @@ Useful when you include some classless css libraries which require you to add at Don't skip ~HTML_DOCTYPE~ else it will duplicate the attribute because one extra will be added due to ~xml:lang~ -** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][🔗]] -*Votes* 10 - -I recently discovered the [[https://github.com/gonewest818/dimmer.el][Dimmer]] package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that *is* focused. And of course, you can customize how much it dims and exclude certain buffers. - -I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. - ** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][🔗]] *Votes* 10 @@ -1498,13 +1452,6 @@ https://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opini I assume the same trick applies to other mode-maps as well. -** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][🔗]] -*Votes* 10 - -describe-\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. - -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. - ** u/bopboa [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3][🔗]] *Votes* 10 @@ -1516,15 +1463,6 @@ This is how to have a beacon without installing any packages. (setq window-selection-change-functions '(pulse-line)) #+END_SRC -** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp][🔗]] -*Votes* 10 - -Many of you probably know of this, but I found "indirect buffers" useful. - -When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow ~C-x n s~ into different headings of the file in different windows. - -Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that ~C-x 4 c C-x n s~ did what I wanted. - ** u/badmaxton [[https://www.reddit.com/r/emacs/comments/t3_19ec8v5/comment/t1_kjcu7vp][🔗]] *Votes* 10 @@ -1536,48 +1474,89 @@ Just added this to the ~:init~ section of my embark configuration: #+END_SRC This allows super-convenient marking of entries for later ~embark-all~ using control-tab, instead of having to go first through the ~embark~ menu. (By default, this key binding is mapped to ~file-cache-minibuffer-complete~, which I never use.) -** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][🔗]] +** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][🔗]] *Votes* 10 -Need to remove an element from a list when you're tinkering with elisp? +[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]] -Sometimes when I'm adding and removing elements from hooks or variables like ~completion-at-point-functions~ I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: +Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \~my-movement-transient-map\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \~activate-my-movement-map\~ function is defined to activate this transient map, and it is globally bound to \~C-f\~. + +​ + +This setup allows you to press \~C-f\~ followed by one of the specified keys (\~f\~, \~b\~, \~c\~, \~l\~, \~n\~, \~p\~) to perform the corresponding movement operation. The \~set-transient-map\~ call with a second argument of \~t\~ ensures that the transient map stays active until one of its keys is pressed. + +​ + +This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! + +I didn't want to drop code in the thread so i put it in a gist + +** u/camel_case_t [[https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q][🔗]] +*Votes* 10 + +This is maybe more a macOS tip than an Emacs tip, but it always bothered me that ~C-f~, ~C-b~, etc worked in any text box, but not ~M-f~, etc -- turns out that you can easily change that throughout the OS! + +I created this file and now Emacs keybindings work everywhere: #+BEGIN_SRC elisp -M-x remove-hook +/* ~/Library/KeyBindings/DefaultKeyBinding.dict */ +{ + /* Additional Emacs bindings */ + "~f" = "moveWordForward:"; + "~b" = "moveWordBackward:"; + "~<" = "moveToBeginningOfDocument:"; + "~>" = "moveToEndOfDocument:"; + "~v" = "pageUp:"; + "~d" = "deleteWordForward:"; + "~^h" = "deleteWordBackward:"; + "~\010" = "deleteWordBackward:"; /* Option-backspace */ + "~\177" = "deleteWordBackward:"; /* Option-delete */ +} #+END_SRC -And you've got an interactive interface (using ~completing-read~) for removing arbitrary elements from any list-like variable. It's _technically_ for altering hooks, but you can abuse it to fool around with lists, too. +You can read more here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html -** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][🔗]] +** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][🔗]] *Votes* 10 -I was converting some old ~.odt~ notes files to ~.org~ today, and one of the things I wanted to do was to add two spaces after end of sentence periods for proper sentence navigation. So there I was figuring out a general enough regexp for the nth time and, of course, I regretted not having taken note of this the last time. So I decided to do some searching for a good regexp and write it down this time, since this was obviously shared by someone somewhere. And it turns out Emacs has us covered, and I never knew: ~repunctuate-sentences~. I have no idea if this is new or has always been there. It is new to me. It uses ~query-replace-regexp~, so it's the same experience. And also can be configured for exclusions with ~repunctuate-sentences-filter~. Neat! +I've been slowly accumulating cases for "flexing" the thing at point as a more general ~capitalize-word~ replacement: -** u/slinchisl [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0][🔗]] -*Votes* 10 +#+BEGIN_SRC elisp +;; Stolen from the wiki somewhere +(defun increment-number-at-point () + "Increment the number at point." + (interactive) + (skip-chars-backward "0-9") + (or (looking-at "[0-9]+") + (error "No number at point")) + (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) + +(defun lw-flex () + "Perform smart flexing at point. + +E.g. capitalize or decapitalize the next word, increment number at point." + (interactive) + (let ((case-fold-search nil)) + (call-interactively + (cond ((looking-at "[0-9]+") #'increment-number-at-point) + ((looking-at "[[:lower:]]") #'capitalize-word) + ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) + ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) + ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) + ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) + ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) + ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) + ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) + ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) + (t #'downcase-word))))) -I'm once again reminded of the utility of ~read-key~ for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. +#+END_SRC +I bind it to ~M-c~. -For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as +** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][🔗]] +*Votes* 10 -#+BEGIN_SRC elisp -(defun slot/insert-time () - (interactive) - (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") - (?l "DDmmmYYYY" "%d%b%Y") - (?t "Time" "%H:%M"))) - (key (read-key - (cl-loop for (key label _) in formats - concat (format "[%s] %s " - (propertize (single-key-description key) 'face 'bold) - label))))) - (->> (alist-get key formats) - cl-second - format-time-string - downcase ; Jan -> jan - insert))) -#+END_SRC +I was converting some old ~.odt~ notes files to ~.org~ today, and one of the things I wanted to do was to add two spaces after end of sentence periods for proper sentence navigation. So there I was figuring out a general enough regexp for the nth time and, of course, I regretted not having taken note of this the last time. So I decided to do some searching for a good regexp and write it down this time, since this was obviously shared by someone somewhere. And it turns out Emacs has us covered, and I never knew: ~repunctuate-sentences~. I have no idea if this is new or has always been there. It is new to me. It uses ~query-replace-regexp~, so it's the same experience. And also can be configured for exclusions with ~repunctuate-sentences-filter~. Neat! ** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mo1bz][🔗]] *Votes* 10 @@ -2017,6 +1996,64 @@ If you want to switch between two themes, depending on time of day (e.g. a light #+END_SRC This selects the correct theme when starting Emacs and automatically switch when the times come. +** u/cidra_ [[https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44][🔗]] +*Votes* 10 + +TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([[https://github.com/florommel/custom-css.git][custom-css on GitHub]]) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: + +#+BEGIN_SRC elisp +(x-gtk-debug t) + +#+END_SRC +One thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the ~border-radius~ attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a ~border-radius~ styling on it. I also applied the ~border-radius~ styling on the main window and on the ~decoration~ component (which gives shadowing to the frame) + +https://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5 + +#+BEGIN_SRC elisp +decoration { + border-radius:12px; +} + +window{ + border-radius: 12px; +} + +menubar{ +/* + For some reason the menu bar + gets a border radius as well. + Let's cover it +\*/ + background-color: white; +} + +toolbar { + border-radius: 12px; +} + +#+END_SRC +Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 + +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][🔗]] +*Votes* 9 + +I've recently discovered [[https://github.com/fuxialexander/org-pdftools][~org-pdftools~]] and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function ~org-store-link~: + +\* mark a passage in the pdf, run ~M-x org-store-link~, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. +\* run ~C-c C-l~ in any org-buffer, and it pastes the link and prompts you for a name. + +The installation is easy, you just need to hook it into ~org-mode~: + +#+BEGIN_SRC elisp + (use-package org-pdftools + :after (org pdf-tools) + :hook (org-mode . org-pdftools-setup-link)) + +#+END_SRC +The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (~C-c C-a l~ to list all highlights, ~D~ to delete). + +It has less features than [[https://github.com/org-noter/org-noter][~org-noter~]], but it is more flexible, which is why it suits my use-case better. Unfortunately, it has ~org-noter~ as a dependency, so you will end up loading it either way. + ** u/fv__ [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe][🔗]] *Votes* 9 @@ -2084,27 +2121,36 @@ Or previous-like example with dirs but without needing additional source block: [deleted] -** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][🔗]] +** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][🔗]] *Votes* 9 -M-x ielm Use the repl while learning elisp coding. I had no idea! +A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [[https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f][this gist]] for the details. -** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][🔗]] +** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][🔗]] *Votes* 9 -[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]] - -Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \~my-movement-transient-map\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \~activate-my-movement-map\~ function is defined to activate this transient map, and it is globally bound to \~C-f\~. +#+BEGIN_SRC elisp +(defun copy-source-for-reddit () + (interactive) + (let ((contents (buffer-substring (point) (mark)))) + (with-temp-buffer + (insert contents) + (mark-whole-buffer) + (indent-rigidly (point) (mark) 4 t) + (mark-whole-buffer) + (kill-ring-save 0 0 t)))) -​ +#+END_SRC +A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. -This setup allows you to press \~C-f\~ followed by one of the specified keys (\~f\~, \~b\~, \~c\~, \~l\~, \~n\~, \~p\~) to perform the corresponding movement operation. The \~set-transient-map\~ call with a second argument of \~t\~ ensures that the transient map stays active until one of its keys is pressed. +** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp][🔗]] +*Votes* 9 -​ +Many of you probably know of this, but I found "indirect buffers" useful. -This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! +When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow ~C-x n s~ into different headings of the file in different windows. -I didn't want to drop code in the thread so i put it in a gist +Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that ~C-x 4 c C-x n s~ did what I wanted. ** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_18mplfa/comment/t1_ke5xr5j][🔗]] *Votes* 9 @@ -2115,6 +2161,19 @@ This makes stack-outputs of debug-buffers much more readable: (setopt debugger-stack-frame-as-list t) #+END_SRC +** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][🔗]] +*Votes* 9 + +Need to remove an element from a list when you're tinkering with elisp? + +Sometimes when I'm adding and removing elements from hooks or variables like ~completion-at-point-functions~ I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: + +#+BEGIN_SRC elisp +M-x remove-hook + +#+END_SRC +And you've got an interactive interface (using ~completing-read~) for removing arbitrary elements from any list-like variable. It's _technically_ for altering hooks, but you can abuse it to fool around with lists, too. + ** u/Netherus [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7][🔗]] *Votes* 9 @@ -2129,43 +2188,6 @@ If you have two buffers open in one frame, where one contains just a few lines a And if you want to balance these two buffers again just use ~C-x +~ -** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][🔗]] -*Votes* 9 - -I've been slowly accumulating cases for "flexing" the thing at point as a more general ~capitalize-word~ replacement: - -#+BEGIN_SRC elisp -;; Stolen from the wiki somewhere -(defun increment-number-at-point () - "Increment the number at point." - (interactive) - (skip-chars-backward "0-9") - (or (looking-at "[0-9]+") - (error "No number at point")) - (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) - -(defun lw-flex () - "Perform smart flexing at point. - -E.g. capitalize or decapitalize the next word, increment number at point." - (interactive) - (let ((case-fold-search nil)) - (call-interactively - (cond ((looking-at "[0-9]+") #'increment-number-at-point) - ((looking-at "[[:lower:]]") #'capitalize-word) - ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) - ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) - ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) - ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) - ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) - ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) - ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) - ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) - (t #'downcase-word))))) - -#+END_SRC -I bind it to ~M-c~. - ** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][🔗]] *Votes* 9 @@ -2571,11 +2593,6 @@ tell application "System Events" end tell #+END_SRC -** u/hunajakettu [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f][🔗]] -*Votes* 9 - -It is the only thing that keeps me sane in a Windows shop. - \** u/attento_redaz [[https://www.reddit.com/r/emacs/comments/t3_wqjare/comment/t1_iku77h0][🔗]] \*Votes* 9 @@ -2641,12 +2658,6 @@ See the repo for more examples and to download. The notes of getting it working In case you can't tell I *really* like emacs and it's client server model. -** u/LionyxML [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72][🔗]] -*Votes* 9 - -A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. -[[https://www.rahuljuliato.com/posts/lemacs][https://www.rahuljuliato.com/posts/lemacs]] - ** u/emacsomancer [[https://www.reddit.com/r/emacs/comments/t3_gqsz8u/comment/t1_fs5sq09][🔗]] *Votes* 9 @@ -2660,30 +2671,10 @@ Each person gets a different colour to indicate the part of the file they’re e https://imgur.com/a/zvfLpdH -** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][🔗]] +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][🔗]] *Votes* 9 -I totally forgot about ~use-package-compute-statistics t~ and (M-x) ~use-package-report~. This helped me optimizing my startup time from around 3 seconds to less than a second. - -** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][🔗]] -*Votes* 8 - -I've recently discovered [[https://github.com/fuxialexander/org-pdftools][~org-pdftools~]] and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function ~org-store-link~: - -\* mark a passage in the pdf, run ~M-x org-store-link~, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. -\* run ~C-c C-l~ in any org-buffer, and it pastes the link and prompts you for a name. - -The installation is easy, you just need to hook it into ~org-mode~: - -#+BEGIN_SRC elisp - (use-package org-pdftools - :after (org pdf-tools) - :hook (org-mode . org-pdftools-setup-link)) - -#+END_SRC -The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (~C-c C-a l~ to list all highlights, ~D~ to delete). - -It has less features than [[https://github.com/org-noter/org-noter][~org-noter~]], but it is more flexible, which is why it suits my use-case better. Unfortunately, it has ~org-noter~ as a dependency, so you will end up loading it either way. +For people who need to do a quick calculations from time to time but struggle using ~M-x calc~, try ~M-x quick-calc~. You can enter expressions such as ~2*3.4+5~, and the result will be shown and put into your clipboard. ** u/meedstrom [[https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro][🔗]] *Votes* 8 @@ -2709,32 +2700,15 @@ But now you can just add a space after the opening paren ~'(~. This is the new For users of [[https://github.com/dajva/rg.el][rg.el]] (emacs interface to ripgrep) there is [[https://github.com/phiresky/ripgrep-all][rga]] (ripgrep-all) a wrapper around ripgrep that "enables it to search in pdf, docx, sqlite, jpg, movie subtitles (mkv, mp4), etc." You can set the rg executable in the configuration of rg.el like so: ~(setq rg-executable (executable-find "rga")~ to enable search in multiple document types. -** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][🔗]] -*Votes* 8 - -A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [[https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f][this gist]] for the details. - ** u/AdjointFunctor [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx][🔗]] *Votes* 8 I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. https://emacsredux.com/blog/2014/01/01/a-peek-at-emacs-24-dot-4-rectangular-selection/ -** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][🔗]] +** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][🔗]] *Votes* 8 -#+BEGIN_SRC elisp -(defun copy-source-for-reddit () - (interactive) - (let ((contents (buffer-substring (point) (mark)))) - (with-temp-buffer - (insert contents) - (mark-whole-buffer) - (indent-rigidly (point) (mark) 4 t) - (mark-whole-buffer) - (kill-ring-save 0 0 t)))) - -#+END_SRC -A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. +M-x ielm Use the repl while learning elisp coding. I had no idea! ** u/vjgoh [[https://www.reddit.com/r/emacs/comments/t3_18149ql/comment/t1_kahspwz][🔗]] *Votes* 8 @@ -2780,6 +2754,31 @@ I'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ (This should be obvious but note that the JWT is not validated or verified. This is intended for debugging only and the JWT should not be trusted.) +** u/slinchisl [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0][🔗]] +*Votes* 8 + +I'm once again reminded of the utility of ~read-key~ for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. + +For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as + +#+BEGIN_SRC elisp +(defun slot/insert-time () + (interactive) + (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") + (?l "DDmmmYYYY" "%d%b%Y") + (?t "Time" "%H:%M"))) + (key (read-key + (cl-loop for (key label _) in formats + concat (format "[%s] %s " + (propertize (single-key-description key) 'face 'bold) + label))))) + (->> (alist-get key formats) + cl-second + format-time-string + downcase ; Jan -> jan + insert))) +#+END_SRC + ** u/w0ntfix [[https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9][🔗]] *Votes* 8 @@ -3517,6 +3516,11 @@ map super+b send_key ctrl+x @ s b #+END_SRC And voila, super works fine in ~emacs -nw~! Kitty translates ~s-a~ into normal terminal-supported control keybindings ~C-x @ s a~, which Emacs then translates back into ~s-a~. +** u/hunajakettu [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f][🔗]] +*Votes* 8 + +It is the only thing that keeps me sane in a Windows shop. + ** u/habamax [[https://www.reddit.com/r/emacs/comments/t3_13qfepf/comment/t1_jli02ld][🔗]] *Votes* 8 @@ -3795,6 +3799,12 @@ TIL that I can disable ``company`` for some modes, I needed to do it because com #+END_SRC works as intended +** u/LionyxML [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72][🔗]] +*Votes* 8 + +A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. +[[https://www.rahuljuliato.com/posts/lemacs][https://www.rahuljuliato.com/posts/lemacs]] + ** u/agumonkey [[https://www.reddit.com/r/emacs/comments/t3_w3gx6o/comment/t1_ih3s9fl][🔗]] *Votes* 8 @@ -4216,9 +4226,4 @@ This function clears a comint-mode buffer in a dwim fashion by preserving the cu (if (= orig-ln after-ln) (move-to-column col t) (move-beginning-of-line nil)))) -#+END_SRC - -** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][🔗]] -*Votes* 8 - -For people who need to do a quick calculations from time to time but struggle using ~M-x calc~, try ~M-x quick-calc~. You can enter expressions such as ~2*3.4+5~, and the result will be shown and put into your clipboard. \ No newline at end of file +#+END_SRC \ No newline at end of file diff --git a/out_by_year.md b/out_by_year.md index 08be213..cd9dd08 100644 --- a/out_by_year.md +++ b/out_by_year.md @@ -17,7 +17,7 @@ ### u/SlowMovingTarget [🔗](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5) -**Votes** 35 +**Votes** 36 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -51,22 +51,9 @@ Then if you bind `(yas-expand-snippet (yas-lookup-snippet "namespace-surround")) ![img](https://i.redd.it/fbsbbr98smtc1.gif) -### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57) - -**Votes** 19 - -`use-package` has an inbuilt feature that roughly reports the loading times of each package on startup ([`esup`](https://github.com/jschaf/esup) most likely does a better job, if you can get it to run; there are [known issues](https://github.com/alexmurray/emacs-snap/issues/71) on Emacs snap): - -1. put `(setq use-package-compute-statistics t)` at the beginning of your `init.el` -2. restart Emacs -3. do `M-x use-package-report` - -Which package is your biggest time sink and why is it worth it? Mine is [`pdf-tools`](https://github.com/vedang/pdf-tools), but to my knowledge there is simply no better alternative for working with pdfs in emacs. - - ### u/vkazanov [🔗](https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y) -**Votes** 17 +**Votes** 18 A dump of my Emacs-related principles after 18 years of tinkering: @@ -83,9 +70,22 @@ A dump of my Emacs-related principles after 18 years of tinkering: I am a beginner though, things might change. +### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57) + +**Votes** 18 + +`use-package` has an inbuilt feature that roughly reports the loading times of each package on startup ([`esup`](https://github.com/jschaf/esup) most likely does a better job, if you can get it to run; there are [known issues](https://github.com/alexmurray/emacs-snap/issues/71) on Emacs snap): + +1. put `(setq use-package-compute-statistics t)` at the beginning of your `init.el` +2. restart Emacs +3. do `M-x use-package-report` + +Which package is your biggest time sink and why is it worth it? Mine is [`pdf-tools`](https://github.com/vedang/pdf-tools), but to my knowledge there is simply no better alternative for working with pdfs in emacs. + + ### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e) -**Votes** 13 +**Votes** 14 I recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [which moves the information in a central pop-up instead](https://blog.costan.ro/img/emacs-completion-system/switch-to.png). For me, this meant using the packages: @@ -106,37 +106,35 @@ But regardless what you are using, chances are there already is a suitable `*-po ``` -### u/mlk [🔗](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9) +### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) -**Votes** 13 +**Votes** 12 -I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (`org-agenda-overriding-header`) with a starting asterisk, e.g "\* Current Tasks", "\* Today Agenda\*" etc +I regularly work with different emacs frames on different monitors, and [`framemove`](https://github.com/emacsmirror/framemove) is great for switching between them. It can hook into `windmove` (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: + +\\\* `fm-up-frame`: move to the frame over the current frame \\\* `fm-down-frame`: move to the frame below the current frame \\\* `fm-left-frame`: move to the frame left of the current frame \\\* `fm-right-frame`: move to the frame right of the current frame + +It's not on any of the major package repositories, so you have to install it manually. Thanks to [`emacsmirror`](https://github.com/emacsmirror), this can for example be done as follows using `use-package` and `straight` (adjust bindings to your liking): ```elisp - (defun my/org-agenda-fold() - "fold sections of agenda starting with \"* \" tab" - (interactive) - (setq-local outline-regexp "^\\* ") - (setq-local outline-heading-end-regexp "\n") - (setq-local outline-minor-mode-prefix (kbd "C-'")) - (outline-minor-mode) - (local-set-key outline-minor-mode-prefix outline-mode-prefix-map) - (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children) - (map! - :after evil-org-agenda - :map evil-org-agenda-mode-map - :m "" #'outline-toggle-children - :m "" #'org-agenda-goto - :m "S-" #'org-agenda-switch-to - :m "C-" #'org-agenda-recenter)) - -(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) +(use-package framemove + :straight (:host github :repo "emacsmirror/framemove") + :init + (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom + :bind + (("C-x 5 " . fm-up-frame) + ("C-x 5 " . fm-down-frame) + ("C-x 5 " . fm-left-frame) + ("C-x 5 " . fm-right-frame))) + ``` +edit: The only thing I don't understand is why setting `framemove-hook-into-windmove` to `t` doesn't work in via `:config` or `:custom`. The package is loaded, `C-h f` confirms that `fm-up-frame` exists, but `C-h v` doesn't know `framemove-hook-into-windmove`. `framemove-hook-into-windmove` exists after I run `fm-up-frame`, but then it's set to `nil` and not `t`. + ### u/remillard [🔗](https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he) -**Votes** 13 +**Votes** 12 I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. @@ -149,37 +147,57 @@ Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt l ### u/geza42 [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1) -**Votes** 13 +**Votes** 12 If you use an LSP server with semantic highlighting, it's worth checking out the value of `font-lock-maximum-decoration`. For example, I use `c++-mode` with `lsp-mode` (with clangd), I decreased `font-lock-maximum-decoration` to `2`, and I didn't notice any highlighting difference (because the lost highlighting by `c++-mode` gets highlighted by `lsp-mode`), while `c++-mode` font-locking become faster (`c++-mode` 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ -### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) +### u/NiceElk55 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9) -**Votes** 11 +**Votes** 12 -I regularly work with different emacs frames on different monitors, and [`framemove`](https://github.com/emacsmirror/framemove) is great for switching between them. It can hook into `windmove` (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: +I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about `C-h`. Say you want to use rectangle commands and remember they start with `C-x r`, but can't remember anything after. Just enter `C-x r`, followed by `C-h`. It will list all the keys under that prefix. Seems to work with any prefix key like `M-s`, `C-c`, etc. -\\\* `fm-up-frame`: move to the frame over the current frame \\\* `fm-down-frame`: move to the frame below the current frame \\\* `fm-left-frame`: move to the frame left of the current frame \\\* `fm-right-frame`: move to the frame right of the current frame +A related thing is that you can explore the keys for a major/minor mode with `C-h b`, `describe-bindings`. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. -It's not on any of the major package repositories, so you have to install it manually. Thanks to [`emacsmirror`](https://github.com/emacsmirror), this can for example be done as follows using `use-package` and `straight` (adjust bindings to your liking): -```elisp -(use-package framemove - :straight (:host github :repo "emacsmirror/framemove") - :init - (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom - :bind - (("C-x 5 " . fm-up-frame) - ("C-x 5 " . fm-down-frame) - ("C-x 5 " . fm-left-frame) - ("C-x 5 " . fm-right-frame))) +### u/mlk [🔗](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9) + +**Votes** 11 +I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (`org-agenda-overriding-header`) with a starting asterisk, e.g "\* Current Tasks", "\* Today Agenda\*" etc + +```elisp + (defun my/org-agenda-fold() + "fold sections of agenda starting with \"* \" tab" + (interactive) + (setq-local outline-regexp "^\\* ") + (setq-local outline-heading-end-regexp "\n") + (setq-local outline-minor-mode-prefix (kbd "C-'")) + (outline-minor-mode) + (local-set-key outline-minor-mode-prefix outline-mode-prefix-map) + (org-defkey org-agenda-mode-map [(tab)] #'outline-toggle-children) + (map! + :after evil-org-agenda + :map evil-org-agenda-mode-map + :m "" #'outline-toggle-children + :m "" #'org-agenda-goto + :m "S-" #'org-agenda-switch-to + :m "C-" #'org-agenda-recenter)) + +(add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) ``` -edit: The only thing I don't understand is why setting `framemove-hook-into-windmove` to `t` doesn't work in via `:config` or `:custom`. The package is loaded, `C-h f` confirms that `fm-up-frame` exists, but `C-h v` doesn't know `framemove-hook-into-windmove`. `framemove-hook-into-windmove` exists after I run `fm-up-frame`, but then it's set to `nil` and not `t`. + +### u/thetemp\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) + +**Votes** 11 + +I recently discovered the [Dimmer](https://github.com/gonewest818/dimmer.el) package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that **is** focused. And of course, you can customize how much it dims and exclude certain buffers. + +I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. ### u/sauntcartas [🔗](https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9) @@ -209,101 +227,45 @@ A minor annoyance was that an unwanted link to whatever file location I happened I've just started to use macros. They are amazing. Here are my tips. C-x -( to start recording. C-x-) to stop recording. F4 to run last recorded macro. Always start at the beginning of a line. Always move by words or lines. If you go forward two chars and the next line needs you to go forward three chars, the macro won't work. Always return to the beginning of the line. For added awesome move down to the next line, positioning yourself to use the macro again. -### u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1933co6/comment/t1_khe4dq6) +### u/saltwaterflyguy [🔗](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) **Votes** 11 -I have long had convenience bindings for `org-emphasize` like `super-i` for *italic*, that match system bindings. But I always wanted these to **be smarter**, i.e. do something useful when there is no text selected. Something like intelligently toggling emphasis depending on whether you were already in the right kind of emphasized text, or just emphasize the word at point if not. +describe-\\\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. -[Check out my solution](https://gist.github.com/jdtsmith/55e6a660dd4c0779a600ac81bf9bfc23) (scroll down to see how it acts). Will miss this behavior in other apps! +If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. -### u/algor512 [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kg4ni5d) +### u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1933co6/comment/t1_khe4dq6) **Votes** 11 -Recently I discovered that `C-h C-q` (or `M-x help-quick`) opens a small window showing \\\*Quick Help\\\* buffer with a nice overview of some basic keybindings. It seems that the content of this buffer is configurable via the variable `help-quick-sections`. +I have long had convenience bindings for `org-emphasize` like `super-i` for *italic*, that match system bindings. But I always wanted these to **be smarter**, i.e. do something useful when there is no text selected. Something like intelligently toggling emphasis depending on whether you were already in the right kind of emphasized text, or just emphasize the word at point if not. -I intend to use it as a cheatsheet, reminding me about rare keybindings I always forget; I believe it is easy to make it context-dependent, just by changing the value of `help-quick-sections`. +[Check out my solution](https://gist.github.com/jdtsmith/55e6a660dd4c0779a600ac81bf9bfc23) (scroll down to see how it acts). Will miss this behavior in other apps! -### u/camelcaset [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q) +### u/algor512 [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kg4ni5d) **Votes** 11 -This is maybe more a macOS tip than an Emacs tip, but it always bothered me that `C-f`, `C-b`, etc worked in any text box, but not `M-f`, etc – turns out that you can easily change that throughout the OS! - -I created this file and now Emacs keybindings work everywhere: - -```elisp -/* ~/Library/KeyBindings/DefaultKeyBinding.dict */ -{ - /* Additional Emacs bindings */ - "~f" = "moveWordForward:"; - "~b" = "moveWordBackward:"; - "~<" = "moveToBeginningOfDocument:"; - "~>" = "moveToEndOfDocument:"; - "~v" = "pageUp:"; - "~d" = "deleteWordForward:"; - "~^h" = "deleteWordBackward:"; - "~\010" = "deleteWordBackward:"; /* Option-backspace */ - "~\177" = "deleteWordBackward:"; /* Option-delete */ -} - -``` +Recently I discovered that `C-h C-q` (or `M-x help-quick`) opens a small window showing \\\*Quick Help\\\* buffer with a nice overview of some basic keybindings. It seems that the content of this buffer is configurable via the variable `help-quick-sections`. -You can read more here: +I intend to use it as a cheatsheet, reminding me about rare keybindings I always forget; I believe it is easy to make it context-dependent, just by changing the value of `help-quick-sections`. -### u/NiceElk55 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9) +### u/konrad1977 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i) **Votes** 11 -I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about `C-h`. Say you want to use rectangle commands and remember they start with `C-x r`, but can't remember anything after. Just enter `C-x r`, followed by `C-h`. It will list all the keys under that prefix. Seems to work with any prefix key like `M-s`, `C-c`, etc. - -A related thing is that you can explore the keys for a major/minor mode with `C-h b`, `describe-bindings`. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. +I totally forgot about `use-package-compute-statistics t` and (M-x) `use-package-report`. This helped me optimizing my startup time from around 3 seconds to less than a second. -### u/cidra\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44) +### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd) **Votes** 11 -TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([custom-css on GitHub](https://github.com/florommel/custom-css.git)) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: - -```elisp -(x-gtk-debug t) - -``` - -One thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the `border-radius` attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a `border-radius` styling on it. I also applied the `border-radius` styling on the main window and on the `decoration` component (which gives shadowing to the frame) - -![img](https://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5) - -```elisp -decoration { - border-radius:12px; -} - -window{ - border-radius: 12px; -} - -menubar{ -/* - For some reason the menu bar - gets a border radius as well. - Let's cover it -\*/ - background-color: white; -} - -toolbar { - border-radius: 12px; -} - -``` - -Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 +I just found out that `M-x make-frame` creates the frame on the monitor where the mouse cursor is. So for people who use multiple monitors, one alternative to `M-x make-frame-on-monitor` and selecting the monitor is to simply have the mouse on the monitor you want. ### u/fuzzbomb23 [🔗](https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7) @@ -343,71 +305,153 @@ Useful when you include some classless css libraries which require you to add at Don't skip `HTML_DOCTYPE` else it will duplicate the attribute because one extra will be added due to `xml:lang` -### u/thetemp\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) +### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) **Votes** 10 -I recently discovered the [Dimmer](https://github.com/gonewest818/dimmer.el) package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that **is** focused. And of course, you can customize how much it dims and exclude certain buffers. +Not from me, but I just wanted to share /u/arthurno1 one-line tip to get `which-key` to work with `dired` (see screenshot in linked post): -I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. + +I assume the same trick applies to other mode-maps as well. -### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) + +### u/bopboa [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3) **Votes** 10 -Not from me, but I just wanted to share /u/arthurno1 one-line tip to get `which-key` to work with `dired` (see screenshot in linked post): +This is how to have a beacon without installing any packages. - +```elisp +(defun pulse-line (_) + (pulse-momentary-highlight-one-line (point))) +(setq window-selection-change-functions '(pulse-line)) +``` -I assume the same trick applies to other mode-maps as well. +### u/badmaxton [🔗](https://www.reddit.com/r/emacs/comments/t3_19ec8v5/comment/t1_kjcu7vp) -### u/saltwaterflyguy [🔗](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) +**Votes** 10 + +Just added this to the `:init` section of my embark configuration: + +```elisp +(define-key minibuffer-local-map [C-tab] 'embark-select) + +``` + +This allows super-convenient marking of entries for later `embark-all` using control-tab, instead of having to go first through the `embark` menu. (By default, this key binding is mapped to `file-cache-minibuffer-complete`, which I never use.) + + +### u/lesliesrussell [🔗](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) **Votes** 10 -describe-\\\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. +[transient map for movement](https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf) -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. +Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \\~my-movement-transient-map\\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \\~activate-my-movement-map\\~ function is defined to activate this transient map, and it is globally bound to \\~C-f\\~. + +​ +This setup allows you to press \\~C-f\\~ followed by one of the specified keys (\\~f\\~, \\~b\\~, \\~c\\~, \\~l\\~, \\~n\\~, \\~p\\~) to perform the corresponding movement operation. The \\~set-transient-map\\~ call with a second argument of \\~t\\~ ensures that the transient map stays active until one of its keys is pressed. -### u/bopboa [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3) +​ + +This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! + +I didn't want to drop code in the thread so i put it in a gist + + +### u/camelcaset [🔗](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q) **Votes** 10 -This is how to have a beacon without installing any packages. +This is maybe more a macOS tip than an Emacs tip, but it always bothered me that `C-f`, `C-b`, etc worked in any text box, but not `M-f`, etc – turns out that you can easily change that throughout the OS! + +I created this file and now Emacs keybindings work everywhere: ```elisp -(defun pulse-line (_) - (pulse-momentary-highlight-one-line (point))) -(setq window-selection-change-functions '(pulse-line)) +/* ~/Library/KeyBindings/DefaultKeyBinding.dict */ +{ + /* Additional Emacs bindings */ + "~f" = "moveWordForward:"; + "~b" = "moveWordBackward:"; + "~<" = "moveToBeginningOfDocument:"; + "~>" = "moveToEndOfDocument:"; + "~v" = "pageUp:"; + "~d" = "deleteWordForward:"; + "~^h" = "deleteWordBackward:"; + "~\010" = "deleteWordBackward:"; /* Option-backspace */ + "~\177" = "deleteWordBackward:"; /* Option-delete */ +} + ``` +You can read more here: + -### u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp) +### u/cidra\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44) **Votes** 10 -Many of you probably know of this, but I found "indirect buffers" useful. +TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([custom-css on GitHub](https://github.com/florommel/custom-css.git)) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: -When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow `C-x n s` into different headings of the file in different windows. +```elisp +(x-gtk-debug t) -Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that `C-x 4 c C-x n s` did what I wanted. +``` +One thing that I really wanted to achieve was to get rounded corners in the bottom edges of an Emacs frame using GNOME. To do that it is necessary for the client-side decorations to do so. I tried applying the `border-radius` attribute everywhere but it won't work on the main pane due to it not being a standard GTK component. What I did was putting the toolbar in the bottom position and then apply a `border-radius` styling on it. I also applied the `border-radius` styling on the main window and on the `decoration` component (which gives shadowing to the frame) -### u/badmaxton [🔗](https://www.reddit.com/r/emacs/comments/t3_19ec8v5/comment/t1_kjcu7vp) +![img](https://preview.redd.it/fnf9sp6yoi3e1.png?width=1725&format=png&auto=webp&s=dca1b33886b72e32d445bb02830814357738c2f5) -**Votes** 10 +```elisp +decoration { + border-radius:12px; +} + +window{ + border-radius: 12px; +} + +menubar{ +/* + For some reason the menu bar + gets a border radius as well. + Let's cover it +\*/ + background-color: white; +} + +toolbar { + border-radius: 12px; +} -Just added this to the `:init` section of my embark configuration: +``` + +Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 + + +### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9) + +**Votes** 9 + +I've recently discovered [`org-pdftools`](https://github.com/fuxialexander/org-pdftools) and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function `org-store-link`: + +\\\* mark a passage in the pdf, run `M-x org-store-link`, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. \\\* run `C-c C-l` in any org-buffer, and it pastes the link and prompts you for a name. + +The installation is easy, you just need to hook it into `org-mode`: ```elisp -(define-key minibuffer-local-map [C-tab] 'embark-select) +(use-package org-pdftools + :after (org pdf-tools) + :hook (org-mode . org-pdftools-setup-link)) ``` -This allows super-convenient marking of entries for later `embark-all` using control-tab, instead of having to go first through the `embark` menu. (By default, this key binding is mapped to `file-cache-minibuffer-complete`, which I never use.) +The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (`C-c C-a l` to list all highlights, `D` to delete). + +It has less features than [`org-noter`](https://github.com/org-noter/org-noter), but it is more flexible, which is why it suits my use-case better. Unfortunately, it has `org-noter` as a dependency, so you will end up loading it either way. ### u/fv\_\_ [🔗](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe) @@ -481,66 +525,49 @@ return data; [deleted] -### u/demosthenex [🔗](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) +### u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) **Votes** 9 -M-x ielm Use the repl while learning elisp coding. I had no idea! +A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [this gist](https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f) for the details. -### u/lesliesrussell [🔗](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) +### u/pt-guzzardo [🔗](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) **Votes** 9 -[transient map for movement](https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf) - -Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \\~my-movement-transient-map\\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \\~activate-my-movement-map\\~ function is defined to activate this transient map, and it is globally bound to \\~C-f\\~. - -​ - -This setup allows you to press \\~C-f\\~ followed by one of the specified keys (\\~f\\~, \\~b\\~, \\~c\\~, \\~l\\~, \\~n\\~, \\~p\\~) to perform the corresponding movement operation. The \\~set-transient-map\\~ call with a second argument of \\~t\\~ ensures that the transient map stays active until one of its keys is pressed. - -​ - -This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! - -I didn't want to drop code in the thread so i put it in a gist - - -### u/LionyxML [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72) +```elisp +(defun copy-source-for-reddit () + (interactive) + (let ((contents (buffer-substring (point) (mark)))) + (with-temp-buffer + (insert contents) + (mark-whole-buffer) + (indent-rigidly (point) (mark) 4 t) + (mark-whole-buffer) + (kill-ring-save 0 0 t)))) -**Votes** 9 +``` -A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. [https://www.rahuljuliato.com/posts/lemacs](https://www.rahuljuliato.com/posts/lemacs) +A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. -### u/konrad1977 [🔗](https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i) +### u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp) **Votes** 9 -I totally forgot about `use-package-compute-statistics t` and (M-x) `use-package-report`. This helped me optimizing my startup time from around 3 seconds to less than a second. - - -### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9) - -**Votes** 8 - -I've recently discovered [`org-pdftools`](https://github.com/fuxialexander/org-pdftools) and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function `org-store-link`: +Many of you probably know of this, but I found "indirect buffers" useful. -\\\* mark a passage in the pdf, run `M-x org-store-link`, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. \\\* run `C-c C-l` in any org-buffer, and it pastes the link and prompts you for a name. +When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow `C-x n s` into different headings of the file in different windows. -The installation is easy, you just need to hook it into `org-mode`: +Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that `C-x 4 c C-x n s` did what I wanted. -```elisp -(use-package org-pdftools - :after (org pdf-tools) - :hook (org-mode . org-pdftools-setup-link)) -``` +### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu) -The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (`C-c C-a l` to list all highlights, `D` to delete). +**Votes** 9 -It has less features than [`org-noter`](https://github.com/org-noter/org-noter), but it is more flexible, which is why it suits my use-case better. Unfortunately, it has `org-noter` as a dependency, so you will end up loading it either way. +For people who need to do a quick calculations from time to time but struggle using `M-x calc`, try `M-x quick-calc`. You can enter expressions such as `2*3.4+5`, and the result will be shown and put into your clipboard. ### u/meedstrom [🔗](https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro) @@ -572,13 +599,6 @@ But now you can just add a space after the opening paren `'(`. This is the new c For users of [rg.el](https://github.com/dajva/rg.el) (emacs interface to ripgrep) there is [rga](https://github.com/phiresky/ripgrep-all) (ripgrep-all) a wrapper around ripgrep that "enables it to search in pdf, docx, sqlite, jpg, movie subtitles (mkv, mp4), etc." You can set the rg executable in the configuration of rg.el like so: `(setq rg-executable (executable-find "rga")` to enable search in multiple document types. -### u/JDRiverRun [🔗](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) - -**Votes** 8 - -A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [this gist](https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f) for the details. - - ### u/AdjointFunctor [🔗](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx) **Votes** 8 @@ -586,24 +606,11 @@ A few people have asked about my code to change cursor color when repeat-mode is I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. -### u/pt-guzzardo [🔗](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) +### u/demosthenex [🔗](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) **Votes** 8 -```elisp -(defun copy-source-for-reddit () - (interactive) - (let ((contents (buffer-substring (point) (mark)))) - (with-temp-buffer - (insert contents) - (mark-whole-buffer) - (indent-rigidly (point) (mark) 4 t) - (mark-whole-buffer) - (kill-ring-save 0 0 t)))) - -``` - -A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. +M-x ielm Use the repl while learning elisp coding. I had no idea! ### u/IcyThought [🔗](https://www.reddit.com/r/emacs/comments/t3_1aw6xkc/comment/t1_kriu3ye) @@ -635,6 +642,13 @@ map super+b send_key ctrl+x @ s b And voila, super works fine in `emacs -nw`! Kitty translates `s-a` into normal terminal-supported control keybindings `C-x @ s a`, which Emacs then translates back into `s-a`. +### u/LionyxML [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72) + +**Votes** 8 + +A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. [https://www.rahuljuliato.com/posts/lemacs](https://www.rahuljuliato.com/posts/lemacs) + + ### u/jcubic [🔗](https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksoij65) **Votes** 8 @@ -653,13 +667,6 @@ It works like this: `C-c 0` creates a bookmark and `C-c <1-9>` jumps into a book Just found out about the variable `confirm-kill-emacs`. Never again will I quit emacs by accident, because auctex bound a frequently used function to `C-c C-v` (one key away from `C-x C-c`). -### u/ImJustPassinBy [🔗](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu) - -**Votes** 8 - -For people who need to do a quick calculations from time to time but struggle using `M-x calc`, try `M-x quick-calc`. You can enter expressions such as `2*3.4+5`, and the result will be shown and put into your clipboard. - - ## 2023 @@ -690,20 +697,20 @@ I discovered \\~org-copy-visible\\~ the other day, when I wanted to send somebod That function (which is bound to C-c C-x v by default) let you copy just the outline for the selected region: very useful! -### u/alvarogonzalezs [🔗](https://www.reddit.com/r/emacs/comments/t3_12jexep/comment/t1_jg34ody) +### u/WorldsEndless [🔗](https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw) **Votes** 18 -I'm a big user of `ffap`. I use this function with `M-x` each time I want to open a file whose name is under the cursor. +Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a `BEGIN_SRC` block, is `org-babel-demarcate-block` `(C-c C-v d)`. -But this week I discovered `ffap-bindings`. This function replaces some key bindings to use `ffap` when it makes sense. For example, it replaces `find-file` with `find-file-at-point`, so the usual keybindings are enriched at no cost. +### u/alvarogonzalezs [🔗](https://www.reddit.com/r/emacs/comments/t3_12jexep/comment/t1_jg34ody) -### u/WorldsEndless [🔗](https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw) +**Votes** 18 -**Votes** 17 +I'm a big user of `ffap`. I use this function with `M-x` each time I want to open a file whose name is under the cursor. -Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a `BEGIN_SRC` block, is `org-babel-demarcate-block` `(C-c C-v d)`. +But this week I discovered `ffap-bindings`. This function replaces some key bindings to use `ffap` when it makes sense. For example, it replaces `find-file` with `find-file-at-point`, so the usual keybindings are enriched at no cost. ### u/WorldsEndless [🔗](https://www.reddit.com/r/emacs/comments/t3_1758wua/comment/t1_k4g09iw) @@ -713,25 +720,27 @@ Often when literate programming I want to split up a code block, maybe copy-past `(delete-blank-lines)` `(C-x C-o)` is massively useful; I use it every day for text cleanup. Press it once and it deletes all but one blank line. Press it twice and it deletes that one, too. -### u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z) +### u/alvarogonzalezs [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l) -**Votes** 15 +**Votes** 14 -For `use-package` users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about `esup`, but a built-in capability that makes it very straightforward to find places to optimize your `init.el` for significantly faster start times. +If you need to find all the occurrences of a string in the project files, but only ****on some specific type of files****, you can use `consult-ripgrep` with `-- -t` in the search pattern. -Enable `use-package-compute-statistics` right after you load `use-package`: +For example, If you need occurrences of `fancystr` in files of type `html`, the search pattern should be `fancystr -- -t html` + +From `consult-grep` documentation, command line options can be passed to grep, specified behind `--.` The overall prompt input has the form: ```elisp -(setq use-package-compute-statistics t) +#async-input -- rg-opts#filter-string ``` -Restart emacs, and then invoke `use-package-report`. You'll get a table of the load times for each package that `use-package` manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right `:hook` keyword. +I have just discovered this, and it made my day. ### u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc) -**Votes** 15 +**Votes** 14 Plain old `query-replace` has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain `y~/~n`: @@ -744,22 +753,20 @@ Plain old `query-replace` has many cool features, first of all it respects the a And many more you can see using `?`. -### u/alvarogonzalezs [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l) - -**Votes** 14 +### u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z) -If you need to find all the occurrences of a string in the project files, but only ****on some specific type of files****, you can use `consult-ripgrep` with `-- -t` in the search pattern. +**Votes** 13 -For example, If you need occurrences of `fancystr` in files of type `html`, the search pattern should be `fancystr -- -t html` +For `use-package` users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about `esup`, but a built-in capability that makes it very straightforward to find places to optimize your `init.el` for significantly faster start times. -From `consult-grep` documentation, command line options can be passed to grep, specified behind `--.` The overall prompt input has the form: +Enable `use-package-compute-statistics` right after you load `use-package`: ```elisp -#async-input -- rg-opts#filter-string +(setq use-package-compute-statistics t) ``` -I have just discovered this, and it made my day. +Restart emacs, and then invoke `use-package-report`. You'll get a table of the load times for each package that `use-package` manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right `:hook` keyword. ### u/geza42 [🔗](https://www.reddit.com/r/emacs/comments/t3_11lqkbo/comment/t1_jbe06qv) @@ -834,20 +841,44 @@ I jump into the built-in Elisp files a lot to see how things work. The indentati And now when I visit one of those files, the alignment is always correct. -### u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c) +### u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw) **Votes** 10 -Need to remove an element from a list when you're tinkering with elisp? - -Sometimes when I'm adding and removing elements from hooks or variables like `completion-at-point-functions` I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: +I've been slowly accumulating cases for "flexing" the thing at point as a more general `capitalize-word` replacement: ```elisp -M-x remove-hook +;; Stolen from the wiki somewhere +(defun increment-number-at-point () + "Increment the number at point." + (interactive) + (skip-chars-backward "0-9") + (or (looking-at "[0-9]+") + (error "No number at point")) + (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) + +(defun lw-flex () + "Perform smart flexing at point. + +E.g. capitalize or decapitalize the next word, increment number at point." + (interactive) + (let ((case-fold-search nil)) + (call-interactively + (cond ((looking-at "[0-9]+") #'increment-number-at-point) + ((looking-at "[[:lower:]]") #'capitalize-word) + ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) + ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) + ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) + ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) + ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) + ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) + ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) + ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) + (t #'downcase-word))))) ``` -And you've got an interactive interface (using `completing-read`) for removing arbitrary elements from any list-like variable. It's technically for altering hooks, but you can abuse it to fool around with lists, too. +I bind it to `M-c`. ### u/gusbrs [🔗](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) @@ -857,33 +888,6 @@ And you've got an interactive interface (using `completing-read`) for removing a I was converting some old `.odt` notes files to `.org` today, and one of the things I wanted to do was to add two spaces after end of sentence periods for proper sentence navigation. So there I was figuring out a general enough regexp for the nth time and, of course, I regretted not having taken note of this the last time. So I decided to do some searching for a good regexp and write it down this time, since this was obviously shared by someone somewhere. And it turns out Emacs has us covered, and I never knew: `repunctuate-sentences`. I have no idea if this is new or has always been there. It is new to me. It uses `query-replace-regexp`, so it's the same experience. And also can be configured for exclusions with `repunctuate-sentences-filter`. Neat! -### u/slinchisl [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0) - -**Votes** 10 - -I'm once again reminded of the utility of `read-key` for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. - -For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as - -```elisp -(defun slot/insert-time () - (interactive) - (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") - (?l "DDmmmYYYY" "%d%b%Y") - (?t "Time" "%H:%M"))) - (key (read-key - (cl-loop for (key label _) in formats - concat (format "[%s] %s " - (propertize (single-key-description key) 'face 'bold) - label))))) - (->> (alist-get key formats) - cl-second - format-time-string - downcase ; Jan -> jan - insert))) -``` - - ### u/[deleted] [🔗](https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mo1bz) **Votes** 10 @@ -950,62 +954,38 @@ This makes stack-outputs of debug-buffers much more readable: ``` -### u/Netherus [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7) +### u/leothrix [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c) **Votes** 9 -Just recently found out M-u makes the next word upper case, and the same for M-l for lower case. Maybe nothing fancy, but it's kinda handy for me. +Need to remove an element from a list when you're tinkering with elisp? +Sometimes when I'm adding and removing elements from hooks or variables like `completion-at-point-functions` I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: -### u/frosch03 [🔗](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) +```elisp +M-x remove-hook -**Votes** 9 +``` -Very useful, but I keep forgetting it: +And you've got an interactive interface (using `completing-read`) for removing arbitrary elements from any list-like variable. It's technically for altering hooks, but you can abuse it to fool around with lists, too. -If you have two buffers open in one frame, where one contains just a few lines and otherwise just uses up a lot of space, you can shrink that buffer down just right by using: `C-x -` -And if you want to balance these two buffers again just use `C-x +` +### u/Netherus [🔗](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7) +**Votes** 9 -### u/PriorOutcome [🔗](https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw) +Just recently found out M-u makes the next word upper case, and the same for M-l for lower case. Maybe nothing fancy, but it's kinda handy for me. -**Votes** 9 -I've been slowly accumulating cases for "flexing" the thing at point as a more general `capitalize-word` replacement: +### u/frosch03 [🔗](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) -```elisp -;; Stolen from the wiki somewhere -(defun increment-number-at-point () - "Increment the number at point." - (interactive) - (skip-chars-backward "0-9") - (or (looking-at "[0-9]+") - (error "No number at point")) - (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) - -(defun lw-flex () - "Perform smart flexing at point. - -E.g. capitalize or decapitalize the next word, increment number at point." - (interactive) - (let ((case-fold-search nil)) - (call-interactively - (cond ((looking-at "[0-9]+") #'increment-number-at-point) - ((looking-at "[[:lower:]]") #'capitalize-word) - ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) - ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) - ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) - ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) - ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) - ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) - ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) - ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) - (t #'downcase-word))))) +**Votes** 9 -``` +Very useful, but I keep forgetting it: -I bind it to `M-c`. +If you have two buffers open in one frame, where one contains just a few lines and otherwise just uses up a lot of space, you can shrink that buffer down just right by using: `C-x -` + +And if you want to balance these two buffers again just use `C-x +` ### u/sauntcartas [🔗](https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv) @@ -1034,13 +1014,6 @@ Does anyone have an `aspell` setup with multiple dictionaries? When I try `--extra-dict` option I get an error: `Expected language "en" but got "de"`. -### u/hunajakettu [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f) - -**Votes** 9 - -It is the only thing that keeps me sane in a Windows shop. - - ### u/vjgoh [🔗](https://www.reddit.com/r/emacs/comments/t3_18149ql/comment/t1_kahspwz) **Votes** 8 @@ -1091,6 +1064,33 @@ I'd forgotten about `with-output-to-temp-buffer` which is pretty handy. The `t` (This should be obvious but note that the JWT is not validated or verified. This is intended for debugging only and the JWT should not be trusted.) +### u/slinchisl [🔗](https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0) + +**Votes** 8 + +I'm once again reminded of the utility of `read-key` for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. + +For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as + +```elisp +(defun slot/insert-time () + (interactive) + (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") + (?l "DDmmmYYYY" "%d%b%Y") + (?t "Time" "%H:%M"))) + (key (read-key + (cl-loop for (key label _) in formats + concat (format "[%s] %s " + (propertize (single-key-description key) 'face 'bold) + label))))) + (->> (alist-get key formats) + cl-second + format-time-string + downcase ; Jan -> jan + insert))) +``` + + ### u/w0ntfix [🔗](https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9) **Votes** 8 @@ -1167,6 +1167,13 @@ Maybe not new for anyone but I only recently found out that `C-c ` i With the above in mind, Im also afraid to forget my bindings. I use which-key package so I wrote a function "define-my-keybinding letter fn" which binds the letter to `C-c ` and to "my-bindings" keyset (prefix) which itself is bound to `C-c m`. Basically, if i forget what bindings I use, I just press C-c m and which-key shows me all of MY bindings (yes, it shows them with C-c too but it's mixed with mode bindings so not helpful) +### u/hunajakettu [🔗](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f) + +**Votes** 8 + +It is the only thing that keeps me sane in a Windows shop. + + ### u/habamax [🔗](https://www.reddit.com/r/emacs/comments/t3_13qfepf/comment/t1_jli02ld) **Votes** 8 diff --git a/out_by_year.org b/out_by_year.org index 5ef9ae2..4c08560 100644 --- a/out_by_year.org +++ b/out_by_year.org @@ -20,7 +20,7 @@ :END: *** u/SlowMovingTarget [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5][🔗]] -*Votes* 35 +*Votes* 36 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -50,19 +50,8 @@ Then if you bind ~(yas-expand-snippet (yas-lookup-snippet "namespace-surround")) https://i.redd.it/fbsbbr98smtc1.gif -*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][🔗]] -*Votes* 19 - -~use-package~ has an inbuilt feature that roughly reports the loading times of each package on startup ([[https://github.com/jschaf/esup][~esup~]] most likely does a better job, if you can get it to run; there are [[https://github.com/alexmurray/emacs-snap/issues/71][known issues]] on Emacs snap): - -1. put ~(setq use-package-compute-statistics t)~ at the beginning of your ~init.el~ -2. restart Emacs -3. do ~M-x use-package-report~ - -Which package is your biggest time sink and why is it worth it? Mine is [[https://github.com/vedang/pdf-tools][~pdf-tools~]], but to my knowledge there is simply no better alternative for working with pdfs in emacs. - *** u/vkazanov [[https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y][🔗]] -*Votes* 17 +*Votes* 18 A dump of my Emacs-related principles after 18 years of tinkering: @@ -78,8 +67,19 @@ A dump of my Emacs-related principles after 18 years of tinkering: I am a beginner though, things might change. +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][🔗]] +*Votes* 18 + +~use-package~ has an inbuilt feature that roughly reports the loading times of each package on startup ([[https://github.com/jschaf/esup][~esup~]] most likely does a better job, if you can get it to run; there are [[https://github.com/alexmurray/emacs-snap/issues/71][known issues]] on Emacs snap): + +1. put ~(setq use-package-compute-statistics t)~ at the beginning of your ~init.el~ +2. restart Emacs +3. do ~M-x use-package-report~ + +Which package is your biggest time sink and why is it worth it? Mine is [[https://github.com/vedang/pdf-tools][~pdf-tools~]], but to my knowledge there is simply no better alternative for working with pdfs in emacs. + *** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1fozctm/comment/t1_lpbqo0e][🔗]] -*Votes* 13 +*Votes* 14 I recently got tired of constantly having to move my eyes to the bottom of Emacs, so I switched to posframes, [[https://blog.costan.ro/img/emacs-completion-system/switch-to.png][which moves the information in a central pop-up instead]]. For me, this meant using the packages: @@ -101,8 +101,59 @@ But regardless what you are using, chances are there already is a suitable ~*-po (transient-posframe-mode)) #+END_SRC +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][🔗]] +*Votes* 12 + +I regularly work with different emacs frames on different monitors, and [[https://github.com/emacsmirror/framemove][~framemove~]] is great for switching between them. It can hook into ~windmove~ (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: + +\* ~fm-up-frame~: move to the frame over the current frame +\* ~fm-down-frame~: move to the frame below the current frame +\* ~fm-left-frame~: move to the frame left of the current frame +\* ~fm-right-frame~: move to the frame right of the current frame + +It's not on any of the major package repositories, so you have to install it manually. Thanks to [[https://github.com/emacsmirror][~emacsmirror~]], this can for example be done as follows using ~use-package~ and ~straight~ (adjust bindings to your liking): + +#+BEGIN_SRC elisp + (use-package framemove + :straight (:host github :repo "emacsmirror/framemove") + :init + (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom + :bind + (("C-x 5 " . fm-up-frame) + ("C-x 5 " . fm-down-frame) + ("C-x 5 " . fm-left-frame) + ("C-x 5 " . fm-right-frame))) + +#+END_SRC +edit: The only thing I don't understand is why setting ~framemove-hook-into-windmove~ to ~t~ doesn't work in via ~:config~ or ~:custom~. The package is loaded, ~C-h f~ confirms that ~fm-up-frame~ exists, but ~C-h v~ doesn't know ~framemove-hook-into-windmove~. ~framemove-hook-into-windmove~ exists after I run ~fm-up-frame~, but then it's set to ~nil~ and not ~t~. + +*** u/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][🔗]] +*Votes* 12 + +I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. + +Well, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The "project goto file" (~C-x p f~) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored. + +I suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore. + +Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was. + +*** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1][🔗]] +*Votes* 12 + +If you use an LSP server with semantic highlighting, it's worth checking out the value of ~font-lock-maximum-decoration~. For example, I use ~c++-mode~ with ~lsp-mode~ (with clangd), I decreased ~font-lock-maximum-decoration~ to ~2~, and I didn't notice any highlighting difference (because the lost highlighting by ~c++-mode~ gets highlighted by ~lsp-mode~), while ~c++-mode~ font-locking become faster (~c++-mode~ 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). + +I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ + +*** u/Nice_Elk_55 [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9][🔗]] +*Votes* 12 + +I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about ~C-h~. Say you want to use rectangle commands and remember they start with ~C-x r~, but can't remember anything after. Just enter ~C-x r~, followed by ~C-h~. It will list all the keys under that prefix. Seems to work with any prefix key like ~M-s~, ~C-c~, etc. + +A related thing is that you can explore the keys for a major/minor mode with ~C-h b~, ~describe-bindings~. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. + *** u/mlk [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9][🔗]] -*Votes* 13 +*Votes* 11 I made my agenda collapsible (like org headings) by using outline-minor-mode. To make it work you need to name your agenda heading (~org-agenda-overriding-header~) with a starting asterisk, e.g "* Current Tasks", "* Today Agenda*" etc @@ -128,49 +179,12 @@ I made my agenda collapsible (like org headings) by using outline-minor-mode. To (add-hook 'org-agenda-mode-hook 'my/org-agenda-fold) #+END_SRC -*** u/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][🔗]] -*Votes* 13 - -I thought about making a whole post about this, but it's mostly ancillary appreciation so maybe this is a better place. Anyhow, for anyone working with code projects, I'm finding that project.el is completely supplanting my previously heavy use of Treemacs. I liked Treemacs because it's a very similar feel to the file/project sidebar in Sublime Text and VSCode (and others I'm sure). It was kind of reassuring. And dired is nice for many things, but navigating a lot of directories does get a little tedious compared to just opening nested directories in Treemacs. - -Well, I don't even remember why I started tinkering with project.el. I think I read a post where someone described switching projects, so I set it up, figured couldn't hurt. Man, definitely a good idea. The "project goto file" (~C-x p f~) is insanely convenient. I also have ctags support setup so a quick keybind will let me switch files based on definition, and between the two, I get through files across the project seamlessly. The project find directory is a faster way to direct dired to a place where I do want to see where things are stored. - -I suspect completion is doing a lot of heavy lifting here though too, so a perfectly pristine project.el use might have a different experience, but those are quite common anymore. - -Anyway, I haven't popped open the Treemacs sidebar in weeks now, and just felt like I should write something in case someone was curious about how handy it was. - -*** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksifwh1][🔗]] -*Votes* 13 - -If you use an LSP server with semantic highlighting, it's worth checking out the value of ~font-lock-maximum-decoration~. For example, I use ~c++-mode~ with ~lsp-mode~ (with clangd), I decreased ~font-lock-maximum-decoration~ to ~2~, and I didn't notice any highlighting difference (because the lost highlighting by ~c++-mode~ gets highlighted by ~lsp-mode~), while ~c++-mode~ font-locking become faster (~c++-mode~ 's font-locking works well 99.9% of the time, but sometimes it can become slow in some circumstances, these slowdowns seems to be gone). - -I use:~(setq font-lock-maximum-decoration '((c-mode . 2) (c++-mode . 2) (t . t)))~ - -*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][🔗]] +*** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][🔗]] *Votes* 11 -I regularly work with different emacs frames on different monitors, and [[https://github.com/emacsmirror/framemove][~framemove~]] is great for switching between them. It can hook into ~windmove~ (which means switching to an adjacent window becomes switching to an adjacent frame if no such window exists) and offers the functions: - -\* ~fm-up-frame~: move to the frame over the current frame -\* ~fm-down-frame~: move to the frame below the current frame -\* ~fm-left-frame~: move to the frame left of the current frame -\* ~fm-right-frame~: move to the frame right of the current frame - -It's not on any of the major package repositories, so you have to install it manually. Thanks to [[https://github.com/emacsmirror][~emacsmirror~]], this can for example be done as follows using ~use-package~ and ~straight~ (adjust bindings to your liking): - -#+BEGIN_SRC elisp - (use-package framemove - :straight (:host github :repo "emacsmirror/framemove") - :init - (setq framemove-hook-into-windmove t) ;; doesn't work as :config or :custom - :bind - (("C-x 5 " . fm-up-frame) - ("C-x 5 " . fm-down-frame) - ("C-x 5 " . fm-left-frame) - ("C-x 5 " . fm-right-frame))) +I recently discovered the [[https://github.com/gonewest818/dimmer.el][Dimmer]] package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that *is* focused. And of course, you can customize how much it dims and exclude certain buffers. -#+END_SRC -edit: The only thing I don't understand is why setting ~framemove-hook-into-windmove~ to ~t~ doesn't work in via ~:config~ or ~:custom~. The package is loaded, ~C-h f~ confirms that ~fm-up-frame~ exists, but ~C-h v~ doesn't know ~framemove-hook-into-windmove~. ~framemove-hook-into-windmove~ exists after I run ~fm-up-frame~, but then it's set to ~nil~ and not ~t~. +I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. *** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][🔗]] *Votes* 11 @@ -194,6 +208,13 @@ A minor annoyance was that an unwanted link to whatever file location I happened I've just started to use macros. They are amazing. Here are my tips. C-x -( to start recording. C-x-) to stop recording. F4 to run last recorded macro. Always start at the beginning of a line. Always move by words or lines. If you go forward two chars and the next line needs you to go forward three chars, the macro won't work. Always return to the beginning of the line. For added awesome move down to the next line, positioning yourself to use the macro again. +*** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][🔗]] +*Votes* 11 + +describe-\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. + +If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. + *** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1933co6/comment/t1_khe4dq6][🔗]] *Votes* 11 @@ -208,9 +229,98 @@ Recently I discovered that ~C-h C-q~ (or ~M-x help-quick~) opens a small window I intend to use it as a cheatsheet, reminding me about rare keybindings I always forget; I believe it is easy to make it context-dependent, just by changing the value of ~help-quick-sections~. -*** u/camel_case_t [[https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q][🔗]] +*** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][🔗]] +*Votes* 11 + +I totally forgot about ~use-package-compute-statistics t~ and (M-x) ~use-package-report~. This helped me optimizing my startup time from around 3 seconds to less than a second. + +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd][🔗]] *Votes* 11 +I just found out that ~M-x make-frame~ creates the frame on the monitor where the mouse cursor is. So for people who use multiple monitors, one alternative to ~M-x make-frame-on-monitor~ and selecting the monitor is to simply have the mouse on the monitor you want. + +*** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][🔗]] +*Votes* 10 + +One of my favourite tips for managing my init file is the ~imenu~ support in ~use-package~. It's turned off by default, though: + +#+BEGIN_SRC elisp +(setq use-package-enable-imenu-support t) +#+END_SRC + +Combined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly. + +*** u/winters_here [[https://www.reddit.com/r/emacs/comments/t3_1eaw1ia/comment/t1_leom8fv][🔗]] +*Votes* 10 + +Simple hack to add attributes to the ~~ tag of an exported org file by escaping the quote of the language header. + +#+BEGIN_SRC elisp +#+HTML_DOCTYPE: html5 +#+LANGUAGE: en" data-theme="dark + +#+END_SRC +This when exported to html using ~org-html-export-to-html~ will result in: + +#+BEGIN_SRC elisp + + +#+END_SRC +Useful when you include some classless css libraries which require you to add attributes to directly to ~~ tag. + +Don't skip ~HTML_DOCTYPE~ else it will duplicate the attribute because one extra will be added due to ~xml:lang~ + +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][🔗]] +*Votes* 10 + +Not from me, but I just wanted to share /u/arthurno1 one-line tip to get ~which-key~ to work with ~dired~ (see screenshot in linked post): + +https://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opinionated_porcelain/l2yi5tn/ + +I assume the same trick applies to other mode-maps as well. + +*** u/bopboa [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3][🔗]] +*Votes* 10 + +This is how to have a beacon without installing any packages. + +#+BEGIN_SRC elisp + (defun pulse-line (_) + (pulse-momentary-highlight-one-line (point))) + (setq window-selection-change-functions '(pulse-line)) +#+END_SRC + +*** u/badmaxton [[https://www.reddit.com/r/emacs/comments/t3_19ec8v5/comment/t1_kjcu7vp][🔗]] +*Votes* 10 + +Just added this to the ~:init~ section of my embark configuration: + +#+BEGIN_SRC elisp +(define-key minibuffer-local-map [C-tab] 'embark-select) + +#+END_SRC +This allows super-convenient marking of entries for later ~embark-all~ using control-tab, instead of having to go first through the ~embark~ menu. (By default, this key binding is mapped to ~file-cache-minibuffer-complete~, which I never use.) + +*** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][🔗]] +*Votes* 10 + +[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]] + +Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \~my-movement-transient-map\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \~activate-my-movement-map\~ function is defined to activate this transient map, and it is globally bound to \~C-f\~. + +​ + +This setup allows you to press \~C-f\~ followed by one of the specified keys (\~f\~, \~b\~, \~c\~, \~l\~, \~n\~, \~p\~) to perform the corresponding movement operation. The \~set-transient-map\~ call with a second argument of \~t\~ ensures that the transient map stays active until one of its keys is pressed. + +​ + +This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! + +I didn't want to drop code in the thread so i put it in a gist + +*** u/camel_case_t [[https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q][🔗]] +*Votes* 10 + This is maybe more a macOS tip than an Emacs tip, but it always bothered me that ~C-f~, ~C-b~, etc worked in any text box, but not ~M-f~, etc -- turns out that you can easily change that throughout the OS! I created this file and now Emacs keybindings work everywhere: @@ -233,15 +343,8 @@ I created this file and now Emacs keybindings work everywhere: #+END_SRC You can read more here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html -*** u/Nice_Elk_55 [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyc7kx9][🔗]] -*Votes* 11 - -I used to use the which-key package to discover key bindings, but now have completely dropped it ever since learning about ~C-h~. Say you want to use rectangle commands and remember they start with ~C-x r~, but can't remember anything after. Just enter ~C-x r~, followed by ~C-h~. It will list all the keys under that prefix. Seems to work with any prefix key like ~M-s~, ~C-c~, etc. - -A related thing is that you can explore the keys for a major/minor mode with ~C-h b~, ~describe-bindings~. It used to be pretty useless because it would list every single possible keybinding and accent character, but in newer emacs it's way easier to navigate thanks to folding headings. - *** u/cidra_ [[https://www.reddit.com/r/emacs/comments/t3_1h0zjvq/comment/t1_lzbam44][🔗]] -*Votes* 11 +*Votes* 10 TIL that you can style the GTK components of Emacs by means of simply overriding CSS styling. There's a cool package for that ([[https://github.com/florommel/custom-css.git][custom-css on GitHub]]) but I also discovered that you can easily tweak it "in real time" and without any additional package by invoking the GTK inspector using the following function: @@ -278,90 +381,25 @@ toolbar { #+END_SRC Now I wonder if it's possible to remove the header bar but without removing the shadow behind the frame and behind the context menus. 🤔 -*** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][🔗]] -*Votes* 10 - -One of my favourite tips for managing my init file is the ~imenu~ support in ~use-package~. It's turned off by default, though: - -#+BEGIN_SRC elisp -(setq use-package-enable-imenu-support t) -#+END_SRC - -Combined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly. - -*** u/winters_here [[https://www.reddit.com/r/emacs/comments/t3_1eaw1ia/comment/t1_leom8fv][🔗]] -*Votes* 10 +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][🔗]] +*Votes* 9 -Simple hack to add attributes to the ~~ tag of an exported org file by escaping the quote of the language header. +I've recently discovered [[https://github.com/fuxialexander/org-pdftools][~org-pdftools~]] and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function ~org-store-link~: -#+BEGIN_SRC elisp -#+HTML_DOCTYPE: html5 -#+LANGUAGE: en" data-theme="dark +\* mark a passage in the pdf, run ~M-x org-store-link~, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. +\* run ~C-c C-l~ in any org-buffer, and it pastes the link and prompts you for a name. -#+END_SRC -This when exported to html using ~org-html-export-to-html~ will result in: +The installation is easy, you just need to hook it into ~org-mode~: #+BEGIN_SRC elisp - - -#+END_SRC -Useful when you include some classless css libraries which require you to add attributes to directly to ~~ tag. - -Don't skip ~HTML_DOCTYPE~ else it will duplicate the attribute because one extra will be added due to ~xml:lang~ - -*** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][🔗]] -*Votes* 10 - -I recently discovered the [[https://github.com/gonewest818/dimmer.el][Dimmer]] package and can't believe I didn't try it until now. It subtly dims windows that aren't focused, just enough to draw your eyes to the window that *is* focused. And of course, you can customize how much it dims and exclude certain buffers. - -I love things that reduce cognitive load like this. You don't realize how much time you spent looking for little clues like a solid cursor, until you don't have to anymore. - -*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][🔗]] -*Votes* 10 - -Not from me, but I just wanted to share /u/arthurno1 one-line tip to get ~which-key~ to work with ~dired~ (see screenshot in linked post): - -https://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opinionated_porcelain/l2yi5tn/ - -I assume the same trick applies to other mode-maps as well. - -*** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][🔗]] -*Votes* 10 - -describe-\*. It is one of the most useful feature sets to access documentation for just about everything there is in Emacs. Not sure what key bindings are set for a given mode? M-x describe-mode or C-h m. Need to know what font is begin used for a certain piece of text? M-x describe-char. Need to know how a given command works? M-x describe-command or C-h x. Need to know the value of a given variable? M-x describe-variable or C-h v. - -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. - -*** u/bopboa [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3][🔗]] -*Votes* 10 - -This is how to have a beacon without installing any packages. + (use-package org-pdftools + :after (org pdf-tools) + :hook (org-mode . org-pdftools-setup-link)) -#+BEGIN_SRC elisp - (defun pulse-line (_) - (pulse-momentary-highlight-one-line (point))) - (setq window-selection-change-functions '(pulse-line)) #+END_SRC +The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (~C-c C-a l~ to list all highlights, ~D~ to delete). -*** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp][🔗]] -*Votes* 10 - -Many of you probably know of this, but I found "indirect buffers" useful. - -When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow ~C-x n s~ into different headings of the file in different windows. - -Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that ~C-x 4 c C-x n s~ did what I wanted. - -*** u/badmaxton [[https://www.reddit.com/r/emacs/comments/t3_19ec8v5/comment/t1_kjcu7vp][🔗]] -*Votes* 10 - -Just added this to the ~:init~ section of my embark configuration: - -#+BEGIN_SRC elisp -(define-key minibuffer-local-map [C-tab] 'embark-select) - -#+END_SRC -This allows super-convenient marking of entries for later ~embark-all~ using control-tab, instead of having to go first through the ~embark~ menu. (By default, this key binding is mapped to ~file-cache-minibuffer-complete~, which I never use.) +It has less features than [[https://github.com/org-noter/org-noter][~org-noter~]], but it is more flexible, which is why it suits my use-case better. Unfortunately, it has ~org-noter~ as a dependency, so you will end up loading it either way. *** u/fv__ [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe][🔗]] *Votes* 9 @@ -430,58 +468,41 @@ Or previous-like example with dirs but without needing additional source block: [deleted] -*** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][🔗]] -*Votes* 9 - -M-x ielm Use the repl while learning elisp coding. I had no idea! - -*** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][🔗]] -*Votes* 9 - -[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]] - -Defines a transient keymap for movement controls and sets up a global key binding to activate this transient map. This transient map, \~my-movement-transient-map\~, includes bindings for various movement commands like moving forward or backward by a word or character and moving to the next or previous line. The \~activate-my-movement-map\~ function is defined to activate this transient map, and it is globally bound to \~C-f\~. - -​ - -This setup allows you to press \~C-f\~ followed by one of the specified keys (\~f\~, \~b\~, \~c\~, \~l\~, \~n\~, \~p\~) to perform the corresponding movement operation. The \~set-transient-map\~ call with a second argument of \~t\~ ensures that the transient map stays active until one of its keys is pressed. - -​ - -This is a neat way to create a custom, modal-like interface for movement within Emacs, leveraging your Emacs Lisp skills to tailor your editing environment to your preferences. If you have any specific modifications or additional features you'd like to implement, feel free to ask! - -I didn't want to drop code in the thread so i put it in a gist - -*** u/LionyxML [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72][🔗]] +*** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][🔗]] *Votes* 9 -A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. -[[https://www.rahuljuliato.com/posts/lemacs][https://www.rahuljuliato.com/posts/lemacs]] - -*** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][🔗]] +A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [[https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f][this gist]] for the details. + +*** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][🔗]] *Votes* 9 -I totally forgot about ~use-package-compute-statistics t~ and (M-x) ~use-package-report~. This helped me optimizing my startup time from around 3 seconds to less than a second. +#+BEGIN_SRC elisp +(defun copy-source-for-reddit () + (interactive) + (let ((contents (buffer-substring (point) (mark)))) + (with-temp-buffer + (insert contents) + (mark-whole-buffer) + (indent-rigidly (point) (mark) 4 t) + (mark-whole-buffer) + (kill-ring-save 0 0 t)))) -*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][🔗]] -*Votes* 8 +#+END_SRC +A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. -I've recently discovered [[https://github.com/fuxialexander/org-pdftools][~org-pdftools~]] and it offers everything I need for annotating pdfs in emacs. I mainly use it to enhance the inbuilt function ~org-store-link~: +*** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp][🔗]] +*Votes* 9 -\* mark a passage in the pdf, run ~M-x org-store-link~, and it creates a highlight in the pdf (technically an empty annotation) and copies a link to it. -\* run ~C-c C-l~ in any org-buffer, and it pastes the link and prompts you for a name. +Many of you probably know of this, but I found "indirect buffers" useful. -The installation is easy, you just need to hook it into ~org-mode~: +When I'm in Vim, I've found it useful to sometimes split a buffer into two windows, and use code folding to view different parts of the same file in the two windows. But this doesn't work in Emacs, because the "folding" and "narrow" states of the buffer are synced between the windows in contrast to Vim. One concrete use case I had: I have a huge Org file, and wanted to narrow ~C-x n s~ into different headings of the file in different windows. -#+BEGIN_SRC elisp - (use-package org-pdftools - :after (org pdf-tools) - :hook (org-mode . org-pdftools-setup-link)) +Indirect buffers solve this. It makes two buffers for one file, and these buffers have separate settings for folding, narrowing, etc. But the buffer contents are still synced, so there's no risk of diverging file states. With default keybindings, I found that ~C-x 4 c C-x n s~ did what I wanted. -#+END_SRC -The only thing to keep in mind is that the highlights in the pdf are not automatically deleted, as you delete the link in the org buffer. You have to do that manually in the pdf (~C-c C-a l~ to list all highlights, ~D~ to delete). +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][🔗]] +*Votes* 9 -It has less features than [[https://github.com/org-noter/org-noter][~org-noter~]], but it is more flexible, which is why it suits my use-case better. Unfortunately, it has ~org-noter~ as a dependency, so you will end up loading it either way. +For people who need to do a quick calculations from time to time but struggle using ~M-x calc~, try ~M-x quick-calc~. You can enter expressions such as ~2*3.4+5~, and the result will be shown and put into your clipboard. *** u/meedstrom [[https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro][🔗]] *Votes* 8 @@ -507,32 +528,15 @@ But now you can just add a space after the opening paren ~'(~. This is the new For users of [[https://github.com/dajva/rg.el][rg.el]] (emacs interface to ripgrep) there is [[https://github.com/phiresky/ripgrep-all][rga]] (ripgrep-all) a wrapper around ripgrep that "enables it to search in pdf, docx, sqlite, jpg, movie subtitles (mkv, mp4), etc." You can set the rg executable in the configuration of rg.el like so: ~(setq rg-executable (executable-find "rga")~ to enable search in multiple document types. -*** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][🔗]] -*Votes* 8 - -A few people have asked about my code to change cursor color when repeat-mode is active (i.e. while you are repeating a command). I rely on it. See [[https://gist.github.com/jdtsmith/a169362879388bc1bdf2bbb977782d4f][this gist]] for the details. - *** u/AdjointFunctor [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx][🔗]] *Votes* 8 I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. https://emacsredux.com/blog/2014/01/01/a-peek-at-emacs-24-dot-4-rectangular-selection/ -*** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][🔗]] +*** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][🔗]] *Votes* 8 -#+BEGIN_SRC elisp -(defun copy-source-for-reddit () - (interactive) - (let ((contents (buffer-substring (point) (mark)))) - (with-temp-buffer - (insert contents) - (mark-whole-buffer) - (indent-rigidly (point) (mark) 4 t) - (mark-whole-buffer) - (kill-ring-save 0 0 t)))) - -#+END_SRC -A handy little snippet for exporting code to reddit markdown. Takes the region, prepends four spaces to each line, and then copies it to the kill ring to be pasted in your browser, without modifying the original buffer. +M-x ielm Use the repl while learning elisp coding. I had no idea! *** u/Icy_Thought [[https://www.reddit.com/r/emacs/comments/t3_1aw6xkc/comment/t1_kriu3ye][🔗]] *Votes* 8 @@ -558,6 +562,12 @@ map super+b send_key ctrl+x @ s b #+END_SRC And voila, super works fine in ~emacs -nw~! Kitty translates ~s-a~ into normal terminal-supported control keybindings ~C-x @ s a~, which Emacs then translates back into ~s-a~. +*** u/LionyxML [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_kslwb72][🔗]] +*Votes* 8 + +A blog post regarding my own Emacs config aiming to get the same user experience on both TUI and GUI. +[[https://www.rahuljuliato.com/posts/lemacs][https://www.rahuljuliato.com/posts/lemacs]] + *** u/jcubic [[https://www.reddit.com/r/emacs/comments/t3_1b20xgn/comment/t1_ksoij65][🔗]] *Votes* 8 @@ -572,11 +582,6 @@ It works like this: ~C-c 0~ creates a bookmark and ~C-c <1-9>~ jumps into a book Just found out about the variable ~confirm-kill-emacs~. Never again will I quit emacs by accident, because auctex bound a frequently used function to ~C-c C-v~ (one key away from ~C-x C-c~). -*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][🔗]] -*Votes* 8 - -For people who need to do a quick calculations from time to time but struggle using ~M-x calc~, try ~M-x quick-calc~. You can enter expressions such as ~2*3.4+5~, and the result will be shown and put into your clipboard. - ** 2023 :PROPERTIES: :CUSTOM_ID: 2023 @@ -601,6 +606,11 @@ I discovered \~org-copy-visible\~ the other day, when I wanted to send somebody That function (which is bound to C-c C-x v by default) let you copy just the outline for the selected region: very useful! +*** u/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw][🔗]] +*Votes* 18 + +Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a ~BEGIN_SRC~ block, is ~org-babel-demarcate-block~ ~(C-c C-v d)~. + *** u/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_12jexep/comment/t1_jg34ody][🔗]] *Votes* 18 @@ -608,31 +618,28 @@ I'm a big user of ~ffap~. I use this function with ~M-x~ each time I want to ope But this week I discovered ~ffap-bindings~. This function replaces some key bindings to use ~ffap~ when it makes sense. For example, it replaces ~find-file~ with ~find-file-at-point~, so the usual keybindings are enriched at no cost. -*** u/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw][🔗]] -*Votes* 17 - -Often when literate programming I want to split up a code block, maybe copy-pasted with multiple functions in it, into separate blocks so I can put some text in between them. The command, with cursor within a ~BEGIN_SRC~ block, is ~org-babel-demarcate-block~ ~(C-c C-v d)~. - *** u/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_1758wua/comment/t1_k4g09iw][🔗]] *Votes* 16 ~(delete-blank-lines)~ ~(C-x C-o)~ is massively useful; I use it every day for text cleanup. Press it once and it deletes all but one blank line. Press it twice and it deletes that one, too. -*** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][🔗]] -*Votes* 15 +*** u/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l][🔗]] +*Votes* 14 -For ~use-package~ users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about ~esup~, but a built-in capability that makes it very straightforward to find places to optimize your ~init.el~ for significantly faster start times. +If you need to find all the occurrences of a string in the project files, but only **on some specific type of files**, you can use ~consult-ripgrep~ with ~-- -t~ in the search pattern. -Enable ~use-package-compute-statistics~ right after you load ~use-package~: +For example, If you need occurrences of ~fancystr~ in files of type ~html~, the search pattern should be ~fancystr -- -t html~ + +From ~consult-grep~ documentation, command line options can be passed to grep, specified behind ~--.~ The overall prompt input has the form: #+BEGIN_SRC elisp -(setq use-package-compute-statistics t) +#async-input -- rg-opts#filter-string #+END_SRC -Restart emacs, and then invoke ~use-package-report~. You'll get a table of the load times for each package that ~use-package~ manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right ~:hook~ keyword. +I have just discovered this, and it made my day. *** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jc9t4tc][🔗]] -*Votes* 15 +*Votes* 14 Plain old ~query-replace~ has many cool features, first of all it respects the active region (if it's active it will only query for replacements in the active region). There are many useful keys in addition to plain ~y~/~n~: @@ -644,20 +651,18 @@ Plain old ~query-replace~ has many cool features, first of all it respects the a And many more you can see using ~?~. -*** u/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l][🔗]] -*Votes* 14 - -If you need to find all the occurrences of a string in the project files, but only **on some specific type of files**, you can use ~consult-ripgrep~ with ~-- -t~ in the search pattern. +*** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][🔗]] +*Votes* 13 -For example, If you need occurrences of ~fancystr~ in files of type ~html~, the search pattern should be ~fancystr -- -t html~ +For ~use-package~ users (which I assume is many of us), did you know that profiling is easy to do? I'm not talking about ~esup~, but a built-in capability that makes it very straightforward to find places to optimize your ~init.el~ for significantly faster start times. -From ~consult-grep~ documentation, command line options can be passed to grep, specified behind ~--.~ The overall prompt input has the form: +Enable ~use-package-compute-statistics~ right after you load ~use-package~: #+BEGIN_SRC elisp -#async-input -- rg-opts#filter-string +(setq use-package-compute-statistics t) #+END_SRC -I have just discovered this, and it made my day. +Restart emacs, and then invoke ~use-package-report~. You'll get a table of the load times for each package that ~use-package~ manages. I discovered this and found an immediate way to cut my startup time in half by fixing a few packages that weren't deferred properly by adding the right ~:hook~ keyword. *** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_11lqkbo/comment/t1_jbe06qv][🔗]] *Votes* 13 @@ -722,49 +727,48 @@ I jump into the built-in Elisp files a lot to see how things work. The indentati #+END_SRC And now when I visit one of those files, the alignment is always correct. -*** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][🔗]] +*** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][🔗]] *Votes* 10 -Need to remove an element from a list when you're tinkering with elisp? - -Sometimes when I'm adding and removing elements from hooks or variables like ~completion-at-point-functions~ I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: +I've been slowly accumulating cases for "flexing" the thing at point as a more general ~capitalize-word~ replacement: #+BEGIN_SRC elisp -M-x remove-hook +;; Stolen from the wiki somewhere +(defun increment-number-at-point () + "Increment the number at point." + (interactive) + (skip-chars-backward "0-9") + (or (looking-at "[0-9]+") + (error "No number at point")) + (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) + +(defun lw-flex () + "Perform smart flexing at point. + +E.g. capitalize or decapitalize the next word, increment number at point." + (interactive) + (let ((case-fold-search nil)) + (call-interactively + (cond ((looking-at "[0-9]+") #'increment-number-at-point) + ((looking-at "[[:lower:]]") #'capitalize-word) + ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) + ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) + ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) + ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) + ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) + ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) + ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) + ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) + (t #'downcase-word))))) #+END_SRC -And you've got an interactive interface (using ~completing-read~) for removing arbitrary elements from any list-like variable. It's _technically_ for altering hooks, but you can abuse it to fool around with lists, too. +I bind it to ~M-c~. *** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][🔗]] *Votes* 10 I was converting some old ~.odt~ notes files to ~.org~ today, and one of the things I wanted to do was to add two spaces after end of sentence periods for proper sentence navigation. So there I was figuring out a general enough regexp for the nth time and, of course, I regretted not having taken note of this the last time. So I decided to do some searching for a good regexp and write it down this time, since this was obviously shared by someone somewhere. And it turns out Emacs has us covered, and I never knew: ~repunctuate-sentences~. I have no idea if this is new or has always been there. It is new to me. It uses ~query-replace-regexp~, so it's the same experience. And also can be configured for exclusions with ~repunctuate-sentences-filter~. Neat! -*** u/slinchisl [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0][🔗]] -*Votes* 10 - -I'm once again reminded of the utility of ~read-key~ for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. - -For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as - -#+BEGIN_SRC elisp -(defun slot/insert-time () - (interactive) - (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") - (?l "DDmmmYYYY" "%d%b%Y") - (?t "Time" "%H:%M"))) - (key (read-key - (cl-loop for (key label _) in formats - concat (format "[%s] %s " - (propertize (single-key-description key) 'face 'bold) - label))))) - (->> (alist-get key formats) - cl-second - format-time-string - downcase ; Jan -> jan - insert))) -#+END_SRC - *** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mo1bz][🔗]] *Votes* 10 @@ -821,6 +825,19 @@ This makes stack-outputs of debug-buffers much more readable: (setopt debugger-stack-frame-as-list t) #+END_SRC +*** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][🔗]] +*Votes* 9 + +Need to remove an element from a list when you're tinkering with elisp? + +Sometimes when I'm adding and removing elements from hooks or variables like ~completion-at-point-functions~ I'll often need to tinker with the symbols I've added. You could evaluate some form somewhere, but I like to be lazy and just: + +#+BEGIN_SRC elisp +M-x remove-hook + +#+END_SRC +And you've got an interactive interface (using ~completing-read~) for removing arbitrary elements from any list-like variable. It's _technically_ for altering hooks, but you can abuse it to fool around with lists, too. + *** u/Netherus [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7][🔗]] *Votes* 9 @@ -835,43 +852,6 @@ If you have two buffers open in one frame, where one contains just a few lines a And if you want to balance these two buffers again just use ~C-x +~ -*** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][🔗]] -*Votes* 9 - -I've been slowly accumulating cases for "flexing" the thing at point as a more general ~capitalize-word~ replacement: - -#+BEGIN_SRC elisp -;; Stolen from the wiki somewhere -(defun increment-number-at-point () - "Increment the number at point." - (interactive) - (skip-chars-backward "0-9") - (or (looking-at "[0-9]+") - (error "No number at point")) - (replace-match (number-to-string (1+ (string-to-number (match-string 0)))))) - -(defun lw-flex () - "Perform smart flexing at point. - -E.g. capitalize or decapitalize the next word, increment number at point." - (interactive) - (let ((case-fold-search nil)) - (call-interactively - (cond ((looking-at "[0-9]+") #'increment-number-at-point) - ((looking-at "[[:lower:]]") #'capitalize-word) - ((looking-at "==") (delete-char 1) (insert "!") (forward-char 2)) - ((looking-at "!=") (delete-char 1) (insert "=") (forward-char 2)) - ((looking-at "+") (delete-char 1) (insert "-") (forward-char 1)) - ((looking-at "-") (delete-char 1) (insert "+") (forward-char 1)) - ((looking-at "<=") (delete-char 2) (insert ">=") (forward-char 2)) - ((looking-at ">=") (delete-char 2) (insert "<=") (forward-char 2)) - ((looking-at "<") (delete-char 1) (insert ">") (forward-char 1)) - ((looking-at ">") (delete-char 1) (insert "<") (forward-char 1)) - (t #'downcase-word))))) - -#+END_SRC -I bind it to ~M-c~. - *** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][🔗]] *Votes* 9 @@ -893,11 +873,6 @@ Does anyone have an ~aspell~ setup with multiple dictionaries? When I try ~--extra-dict~ option I get an error: ~Expected language "en" but got "de"~. -*** u/hunajakettu [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f][🔗]] -*Votes* 9 - -It is the only thing that keeps me sane in a Windows shop. - *** u/vjgoh [[https://www.reddit.com/r/emacs/comments/t3_18149ql/comment/t1_kahspwz][🔗]] *Votes* 8 @@ -942,6 +917,31 @@ I'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ (This should be obvious but note that the JWT is not validated or verified. This is intended for debugging only and the JWT should not be trusted.) +*** u/slinchisl [[https://www.reddit.com/r/emacs/comments/t3_11rq2gl/comment/t1_jca66k0][🔗]] +*Votes* 8 + +I'm once again reminded of the utility of ~read-key~ for small functions where one wants a nicer interface for choosing an alternative than universal arguments; taking an optional prompt, it simply reads a key from the keyboard and returns it. + +For example, I recently wanted a function that prints a set of predefined dates for me into the current buffer, and it was as easy as + +#+BEGIN_SRC elisp +(defun slot/insert-time () + (interactive) + (let* ((formats '((?i "ISO 8601" "%Y-%m-%d") + (?l "DDmmmYYYY" "%d%b%Y") + (?t "Time" "%H:%M"))) + (key (read-key + (cl-loop for (key label _) in formats + concat (format "[%s] %s " + (propertize (single-key-description key) 'face 'bold) + label))))) + (->> (alist-get key formats) + cl-second + format-time-string + downcase ; Jan -> jan + insert))) +#+END_SRC + *** u/w0ntfix [[https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9][🔗]] *Votes* 8 @@ -1008,6 +1008,11 @@ Maybe not new for anyone but I only recently found out that ~C-c ~ i With the above in mind, Im also afraid to forget my bindings. I use which-key package so I wrote a function "define-my-keybinding letter fn" which binds the letter to ~C-c ~ and to "my-bindings" keyset (prefix) which itself is bound to ~C-c m~. Basically, if i forget what bindings I use, I just press C-c m and which-key shows me all of MY bindings (yes, it shows them with C-c too but it's mixed with mode bindings so not helpful) +*** u/hunajakettu [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2f683f][🔗]] +*Votes* 8 + +It is the only thing that keeps me sane in a Windows shop. + *** u/habamax [[https://www.reddit.com/r/emacs/comments/t3_13qfepf/comment/t1_jli02ld][🔗]] *Votes* 8