From cf395b4f4c0b06fce2583d623a717d14af62f0d4 Mon Sep 17 00:00:00 2001 From: emacs-reddit-tips-n-tricks-bot Date: Sun, 29 Dec 2024 00:59:52 +0000 Subject: [PATCH] Weekly update from 2024-12-29 --- comments.json | 108 ++++---- out.md | 708 ++++++++++++++++++++++++------------------------ out.org | 670 ++++++++++++++++++++++----------------------- out_by_year.md | 600 ++++++++++++++++++++-------------------- out_by_year.org | 526 +++++++++++++++++------------------ 5 files changed, 1306 insertions(+), 1306 deletions(-) diff --git a/comments.json b/comments.json index 025b906..3df0f2e 100644 --- a/comments.json +++ b/comments.json @@ -1,38 +1,38 @@ { "t1_lui5ao9": { "author": "ImJustPassinBy", - "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.", + "upvotes": 10, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][\ud83d\udd17]] \n*Votes* 10\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": 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. :)", + "upvotes": 37, + "body": "** u/SlowMovingTarget [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr35bm5][\ud83d\udd17]] \n*Votes* 37\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": { "author": "fv__", - "upvotes": 9, - "body": "** u/fv__ [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe][\ud83d\udd17]] \n*Votes* 9\n\nC-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ --force-with-lease~ by default while pushing in magit (P p)", + "upvotes": 8, + "body": "** u/fv__ [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe][\ud83d\udd17]] \n*Votes* 8\n\nC-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ --force-with-lease~ by default while pushing in magit (P p)", "created_datetime": "2024-10-09 20:31:25+00:00" }, "t1_lpbqo0e": { "author": "ImJustPassinBy", - "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", + "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", "created_datetime": "2024-09-28 11:36:58+00:00" }, "t1_lnqelw9": { "author": "mlk", - "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", + "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", "created_datetime": "2024-09-18 13:49:47+00:00" }, "t1_ls4kmt1": { "author": "ilemming", - "upvotes": 9, - "body": "** u/ilemming [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1][\ud83d\udd17]] \n*Votes* 9\n\nYou know that you can use vars in org source blocks that inject some data, like:\n\n#+BEGIN_SRC elisp\n #+begin_src bash :var token=\"bla-bla-bla\" \n echo ${token}\n #+end_src\n\n #+RESULTS:\n : bla-bla-bla\n\n#+END_SRC\nThat can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block.\n\n#+BEGIN_SRC elisp\n #+name: dirs\n #+begin_src bash :results silent\n ls \n #+end_src\n\n #+begin_src js :var data=dirs \n console.log(data)\n #+end_src\n\n#+END_SRC\nBut did you know, you can also use elisp there?\n\n#+BEGIN_SRC elisp\n #+begin_src js :var data=(if (featurep :system 'macos) \"\ud83c\udf4e\" \"\ud83d\udc27\") \n return data;\n #+end_src\n\n #+RESULTS:\n : \ud83c\udf4e\n\n#+END_SRC\nOr previous-like example with dirs but without needing additional source block:\n\n#+BEGIN_SRC elisp\n#+begin_src clojure :var data=(shell-command-to-string \"ls -a ~\") \n;; all dotfiles\n(require '[clojure.string :as str])\n\n(->> (str/split data #\"\\n\")\n (filter (partial re-find #\"^\\.*\"))\n (sort)\n (str/join \"\\n\"))\n#+end_src\n#+END_SRC", + "upvotes": 8, + "body": "** u/ilemming [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1][\ud83d\udd17]] \n*Votes* 8\n\nYou know that you can use vars in org source blocks that inject some data, like:\n\n#+BEGIN_SRC elisp\n #+begin_src bash :var token=\"bla-bla-bla\" \n echo ${token}\n #+end_src\n\n #+RESULTS:\n : bla-bla-bla\n\n#+END_SRC\nThat can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block.\n\n#+BEGIN_SRC elisp\n #+name: dirs\n #+begin_src bash :results silent\n ls \n #+end_src\n\n #+begin_src js :var data=dirs \n console.log(data)\n #+end_src\n\n#+END_SRC\nBut did you know, you can also use elisp there?\n\n#+BEGIN_SRC elisp\n #+begin_src js :var data=(if (featurep :system 'macos) \"\ud83c\udf4e\" \"\ud83d\udc27\") \n return data;\n #+end_src\n\n #+RESULTS:\n : \ud83c\udf4e\n\n#+END_SRC\nOr previous-like example with dirs but without needing additional source block:\n\n#+BEGIN_SRC elisp\n#+begin_src clojure :var data=(shell-command-to-string \"ls -a ~\") \n;; all dotfiles\n(require '[clojure.string :as str])\n\n(->> (str/split data #\"\\n\")\n (filter (partial re-find #\"^\\.*\"))\n (sort)\n (str/join \"\\n\"))\n#+end_src\n#+END_SRC", "created_datetime": "2024-10-16 00:25:20+00:00" }, "t1_lmzbyro": { @@ -43,14 +43,14 @@ }, "t1_llfyzu6": { "author": "ImJustPassinBy", - "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~.", + "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~.", "created_datetime": "2024-09-04 10:03:14+00:00" }, "t1_lkrhqf7": { "author": "fuzzbomb23", - "upvotes": 10, - "body": "** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][\ud83d\udd17]] \n*Votes* 10\n\nOne of my favourite tips for managing my init file is the ~imenu~ support in ~use-package~. It's turned off by default, though:\n\n#+BEGIN_SRC elisp\n(setq use-package-enable-imenu-support t)\n#+END_SRC\n\nCombined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly.", + "upvotes": 11, + "body": "** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][\ud83d\udd17]] \n*Votes* 11\n\nOne of my favourite tips for managing my init file is the ~imenu~ support in ~use-package~. It's turned off by default, though:\n\n#+BEGIN_SRC elisp\n(setq use-package-enable-imenu-support t)\n#+END_SRC\n\nCombined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly.", "created_datetime": "2024-08-31 00:51:51+00:00" }, "t1_lfskmro": { @@ -61,8 +61,8 @@ }, "t1_lfsffnb": { "author": "[deleted]", - "upvotes": 9, - "body": "** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb][\ud83d\udd17]] \n*Votes* 9\n\n[deleted]", + "upvotes": 8, + "body": "** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb][\ud83d\udd17]] \n*Votes* 8\n\n[deleted]", "created_datetime": "2024-07-31 09:52:36+00:00" }, "t1_lg6q2rq": { @@ -85,14 +85,14 @@ }, "t1_l9cmdp9": { "author": "sauntcartas", - "upvotes": 11, - "body": "** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][\ud83d\udd17]] \n*Votes* 11\n\nI started using org-capture when I started my current job several years ago. I recorded my daily activities using this template:\n\n#+BEGIN_SRC elisp\n(setq org-capture-templates\n '((\"d\" \"Done\" entry (file+olp+datetree \"~/org/done.org\"))))\n\n#+END_SRC\nA minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and _finally_ was able to work it out after poring over the documentation for the ~org-capture-templates~ variable. It turns out the default \"template\" for the ~entry~ capture type is ~\"* %?\\n%a\"~, where the code ~%a~ means \"annotation,\" ie, a link to the file location. So I just had to change my definition to this:\n\n#+BEGIN_SRC elisp\n(setq org-capture-templates\n '((\"d\" \"Done\" entry (file+olp+datetree \"~/org/done.org\") \"* %?\")))\n#+END_SRC", + "upvotes": 12, + "body": "** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][\ud83d\udd17]] \n*Votes* 12\n\nI started using org-capture when I started my current job several years ago. I recorded my daily activities using this template:\n\n#+BEGIN_SRC elisp\n(setq org-capture-templates\n '((\"d\" \"Done\" entry (file+olp+datetree \"~/org/done.org\"))))\n\n#+END_SRC\nA minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and _finally_ was able to work it out after poring over the documentation for the ~org-capture-templates~ variable. It turns out the default \"template\" for the ~entry~ capture type is ~\"* %?\\n%a\"~, where the code ~%a~ means \"annotation,\" ie, a link to the file location. So I just had to change my definition to this:\n\n#+BEGIN_SRC elisp\n(setq org-capture-templates\n '((\"d\" \"Done\" entry (file+olp+datetree \"~/org/done.org\") \"* %?\")))\n#+END_SRC", "created_datetime": "2024-06-19 19:02:38+00:00" }, "t1_l8d30q3": { "author": "JDRiverRun", - "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.", + "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.", "created_datetime": "2024-06-13 01:47:13+00:00" }, "t1_l687lg9": { @@ -103,8 +103,8 @@ }, "t1_l33y04q": { "author": "ImJustPassinBy", - "upvotes": 10, - "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][\ud83d\udd17]] \n*Votes* 10\n\nNot 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):\n\nhttps://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opinionated_porcelain/l2yi5tn/\n\nI assume the same trick applies to other mode-maps as well.", + "upvotes": 12, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][\ud83d\udd17]] \n*Votes* 12\n\nNot 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):\n\nhttps://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opinionated_porcelain/l2yi5tn/\n\nI assume the same trick applies to other mode-maps as well.", "created_datetime": "2024-05-08 10:04:15+00:00" }, "t1_l359pqx": { @@ -127,26 +127,26 @@ }, "t1_kywimnf": { "author": "geza42", - "upvotes": 21, - "body": "** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1c0gg7n/comment/t1_kywimnf][\ud83d\udd17]] \n*Votes* 21\n\nYasnippet has the capability of surrounding. For example, if you have this C++ namespace snippet:\n\n#+BEGIN_SRC elisp\n# -*- mode: snippet -*-\n# name: namespace-surround\n# key: ns\n# --\nnamespace ${1}${1:$(if (> (length yas-text) 0) \" {\" \"{\")}\n~yas-selected-text~$0\n} // namespace${1:$(if (> (length yas-text) 0) (concat \" \" (substring-no-properties yas-text)) \"\")}\n\n#+END_SRC\nThen if you bind ~(yas-expand-snippet (yas-lookup-snippet \"namespace-surround\"))~ to some key, then you can select some code, press your keybinding, and the selected code will be surrounded by \"namespace NAME {\" and \"} // namespace NAME\".\n\nhttps://i.redd.it/fbsbbr98smtc1.gif", + "upvotes": 22, + "body": "** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1c0gg7n/comment/t1_kywimnf][\ud83d\udd17]] \n*Votes* 22\n\nYasnippet has the capability of surrounding. For example, if you have this C++ namespace snippet:\n\n#+BEGIN_SRC elisp\n# -*- mode: snippet -*-\n# name: namespace-surround\n# key: ns\n# --\nnamespace ${1}${1:$(if (> (length yas-text) 0) \" {\" \"{\")}\n~yas-selected-text~$0\n} // namespace${1:$(if (> (length yas-text) 0) (concat \" \" (substring-no-properties yas-text)) \"\")}\n\n#+END_SRC\nThen if you bind ~(yas-expand-snippet (yas-lookup-snippet \"namespace-surround\"))~ to some key, then you can select some code, press your keybinding, and the selected code will be surrounded by \"namespace NAME {\" and \"} // namespace NAME\".\n\nhttps://i.redd.it/fbsbbr98smtc1.gif", "created_datetime": "2024-04-10 10:43:05+00:00" }, "t1_kxur0j8": { "author": "saltwaterflyguy", - "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.", + "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.", "created_datetime": "2024-04-03 13:59:07+00:00" }, "t1_kuo1f9y": { "author": "vkazanov", - "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.", + "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.", "created_datetime": "2024-03-13 12:33:07+00:00" }, "t1_ktogga6": { "author": "demosthenex", - "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!", + "upvotes": 10, + "body": "** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][\ud83d\udd17]] \n*Votes* 10\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": { @@ -175,8 +175,8 @@ }, "t1_kibmgv2": { "author": "lesliesrussell", - "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", + "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", "created_datetime": "2024-01-17 19:20:18+00:00" }, "t1_khe4dq6": { @@ -217,8 +217,8 @@ }, "t1_k8dlt4c": { "author": "leothrix", - "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.", + "upvotes": 11, + "body": "** u/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][\ud83d\udd17]] \n*Votes* 11\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": { @@ -247,8 +247,8 @@ }, "t1_jxekm3a": { "author": "frosch03", - "upvotes": 9, - "body": "** u/frosch03 [[https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a][\ud83d\udd17]] \n*Votes* 9\n\nVery useful, but I keep forgetting it:\n\nIf 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 -~\n\nAnd if you want to balance these two buffers again just use ~C-x +~", + "upvotes": 8, + "body": "** u/frosch03 [[https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a][\ud83d\udd17]] \n*Votes* 8\n\nVery useful, but I keep forgetting it:\n\nIf 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 -~\n\nAnd if you want to balance these two buffers again just use ~C-x +~", "created_datetime": "2023-08-23 12:37:15+00:00" }, "t1_jwff8bw": { @@ -259,8 +259,8 @@ }, "t1_jpwn2ts": { "author": "gusbrs", - "upvotes": 10, - "body": "** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][\ud83d\udd17]] \n*Votes* 10\n\nI 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!", + "upvotes": 9, + "body": "** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][\ud83d\udd17]] \n*Votes* 9\n\nI 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!", "created_datetime": "2023-06-28 20:43:42+00:00" }, "t1_jl5zu6z": { @@ -271,8 +271,8 @@ }, "t1_jhrzybp": { "author": "BunnyLushington", - "upvotes": 8, - "body": "** u/BunnyLushington [[https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp][\ud83d\udd17]] \n*Votes* 8\n\nI found myself debugging [[https://jwt.io][JWTs]] earlier this week and whomped up a little function to decode them from a region into a help buffer.\n\n#+BEGIN_SRC elisp\n(defun ii/decode-jwt (start end &optional jwt)\n \"Decode JWT in region and print to help buffer.\"\n (interactive \"r\")\n (let* ((tok (if jwt jwt\n (buffer-substring start end)))\n (data (s-split \"\\\\.\" tok))\n (header (car data))\n (claims (cadr data)))\n(with-temp-buffer\n (insert (format \"%s\\n\\n%s\"\n (base64-decode-string header t)\n (base64-decode-string claims t)))\n (json-pretty-print-buffer)\n (with-output-to-temp-buffer \"*JWT*\"\n (princ (buffer-string)))))\n t)\n#+END_SRC\n\nI'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ at the end is there just to suppress an overly large echo area message.\n\n(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.)", + "upvotes": 9, + "body": "** u/BunnyLushington [[https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp][\ud83d\udd17]] \n*Votes* 9\n\nI found myself debugging [[https://jwt.io][JWTs]] earlier this week and whomped up a little function to decode them from a region into a help buffer.\n\n#+BEGIN_SRC elisp\n(defun ii/decode-jwt (start end &optional jwt)\n \"Decode JWT in region and print to help buffer.\"\n (interactive \"r\")\n (let* ((tok (if jwt jwt\n (buffer-substring start end)))\n (data (s-split \"\\\\.\" tok))\n (header (car data))\n (claims (cadr data)))\n(with-temp-buffer\n (insert (format \"%s\\n\\n%s\"\n (base64-decode-string header t)\n (base64-decode-string claims t)))\n (json-pretty-print-buffer)\n (with-output-to-temp-buffer \"*JWT*\"\n (princ (buffer-string)))))\n t)\n#+END_SRC\n\nI'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ at the end is there just to suppress an overly large echo area message.\n\n(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.)", "created_datetime": "2023-04-26 12:36:06+00:00" }, "t1_jgwlxuw": { @@ -295,20 +295,20 @@ }, "t1_jf3ohpv": { "author": "sauntcartas", - "upvotes": 9, - "body": "** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][\ud83d\udd17]] \n*Votes* 9\n\nI work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice:\n\n#+BEGIN_SRC elisp\n(defun default-to-main-project (dir)\n (or dir *main-project-dir*))\n\n(advice-add 'projectile-ensure-project :override #'default-to-main-project)\n\n#+END_SRC\nI lose some of the functionality of ~projectile-ensure-project~, but I never used it anyway.", + "upvotes": 10, + "body": "** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][\ud83d\udd17]] \n*Votes* 10\n\nI work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice:\n\n#+BEGIN_SRC elisp\n(defun default-to-main-project (dir)\n (or dir *main-project-dir*))\n\n(advice-add 'projectile-ensure-project :override #'default-to-main-project)\n\n#+END_SRC\nI lose some of the functionality of ~projectile-ensure-project~, but I never used it anyway.", "created_datetime": "2023-04-05 20:53:04+00:00" }, "t1_jc9t4tc": { "author": "PriorOutcome", - "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 ~?~.", + "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 ~?~.", "created_datetime": "2023-03-15 09:20:08+00:00" }, "t1_jca66k0": { "author": "slinchisl", - "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", + "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", "created_datetime": "2023-03-15 11:56:11+00:00" }, "t1_jbe06qv": { @@ -1273,8 +1273,8 @@ }, "t1_lvojz57": { "author": "ImJustPassinBy", - "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.", + "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.", "created_datetime": "2024-11-06 09:43:57+00:00" }, "t1_ksoij65": { @@ -1387,8 +1387,8 @@ }, "t1_lx7y88i": { "author": "konrad1977", - "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.", + "upvotes": 10, + "body": "** u/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][\ud83d\udd17]] \n*Votes* 10\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": { @@ -1411,8 +1411,8 @@ }, "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.", + "upvotes": 10, + "body": "** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd][\ud83d\udd17]] \n*Votes* 10\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 194bf42..ab8e8d9 100644 --- a/out.md +++ b/out.md @@ -1,15 +1,6 @@ -# u/TheDrownedKraken [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_o68i0v/comment/t1_h2rdkkz) - -**Votes** 37 - -Do you think it might be good to make this a little less frequently refreshed? There are usually some great tips that get lost to Reddit’s ephemerality pretty quickly. - -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** 36 +**Votes** 37 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -21,6 +12,15 @@ It's in the manual, and a basic little feature, but really handy. -# 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** 18 +**Votes** 17 -`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/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_vnals8/comment/t1_ie7p6ja) @@ -434,6 +434,21 @@ 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/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 @@ -506,29 +521,6 @@ 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 @@ -547,21 +539,6 @@ 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 @@ -676,6 +653,57 @@ 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) + +**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) + +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/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 + +```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/leothrix [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z) **Votes** 13 @@ -1160,30 +1188,35 @@ 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) +# u/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9) **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 started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: -\\\* `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 +```elisp +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) -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))) +A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and finally was able to work it out after poring over the documentation for the `org-capture-templates` variable. It turns out the default "template" for the `entry` capture type is `"* %?\n%a"`, where the code `%a` means "annotation," ie, a link to the file location. So I just had to change my definition to this: +```elisp +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) ``` -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/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) + +**Votes** 12 + +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 assume the same trick applies to other mode-maps as well. # u/remillard [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he) @@ -1360,77 +1393,59 @@ I used to use the which-key package to discover key bindings, but now have compl 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) +# u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) **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) -``` - +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: -# u/thetemp\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) +\\\* `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 -**Votes** 11 +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): -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. +```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 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. +``` +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/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9) + +# u/fuzzbomb23 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7) **Votes** 11 -I started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: +One of my favourite tips for managing my init file is the `imenu` support in `use-package`. It's turned off by default, though: ```elisp -(setq org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) - +(setq use-package-enable-imenu-support t) ``` -A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and finally was able to work it out after poring over the documentation for the `org-capture-templates` variable. It turns out the default "template" for the `entry` capture type is `"* %?\n%a"`, where the code `%a` means "annotation," ie, a link to the file location. So I just had to change my definition to this: - -```elisp -(setq org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) -``` +Combined with a nice imenu UI (`consult-imenu` and Vertico, say) you can navigate your init file really quickly. -# u/UsualOffice1740 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9) +# u/thetemp\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) **Votes** 11 -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. +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/saltwaterflyguy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) -**Votes** 11 +# u/UsualOffice1740 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9) -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. +**Votes** 11 -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. +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) @@ -1451,6 +1466,22 @@ 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/leothrix [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c) + +**Votes** 11 + +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: + +```elisp +M-x remove-hook + +``` + +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/tryptych [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_w3gx6o/comment/t1_ih6ievs) **Votes** 11 @@ -1564,31 +1595,26 @@ 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/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/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9) +**Votes** 10 -# u/fuzzbomb23 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7) +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`: -**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. -One of my favourite tips for managing my init file is the `imenu` support in `use-package`. It's turned off by default, though: +The installation is easy, you just need to hook it into `org-mode`: ```elisp -(setq use-package-enable-imenu-support t) +(use-package org-pdftools + :after (org pdf-tools) + :hook (org-mode . org-pdftools-setup-link)) + ``` -Combined with a nice imenu UI (`consult-imenu` and Vertico, say) you can navigate your init file really quickly. +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/wintershere [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eaw1ia/comment/t1_leom8fv) @@ -1615,15 +1641,20 @@ 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/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) +# u/saltwaterflyguy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) **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): +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. -I assume the same trick applies to other mode-maps as well. + +# u/demosthenex [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) + +**Votes** 10 + +M-x ielm Use the repl while learning elisp coding. I had no idea! # u/bopboa [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3) @@ -1653,25 +1684,6 @@ 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/lesliesrussell [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) - -**Votes** 10 - -[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/camelcaset [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q) **Votes** 10 @@ -1740,11 +1752,48 @@ E.g. capitalize or decapitalize the next word, increment number at point." I bind it to `M-c`. -# u/gusbrs [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) +# u/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv) **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 work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: + +```elisp +(defun default-to-main-project (dir) + (or dir *main-project-dir*)) + +(advice-add 'projectile-ensure-project :override #'default-to-main-project) + +``` + +I lose some of the functionality of `projectile-ensure-project`, but I never used it anyway. + + +# 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) @@ -2246,6 +2295,13 @@ If you want to switch between two themes, depending on time of day (e.g. a light This selects the correct theme when starting Emacs and automatically switch when the times come. +# u/konrad1977 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i) + +**Votes** 10 + +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) **Votes** 10 @@ -2288,83 +2344,11 @@ toolbar { 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 -(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. - - -# u/fv\_\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe) - -**Votes** 9 - -C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ –force-with-lease~ by default while pushing in magit (P p) - - -# u/ilemming [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1) - -**Votes** 9 - -You know that you can use vars in org source blocks that inject some data, like: - -```elisp -#+begin_src bash :var token="bla-bla-bla" -echo ${token} -``` - - bla-bla-bla - -\#+ENDSRC That can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block. - -```elisp -#+name: dirs -#+begin_src bash :results silent -ls -``` - -```js -console.log(data) -``` - -\#+ENDSRC But did you know, you can also use elisp there? - -```elisp -#+begin_src js :var data=(if (featurep :system 'macos) "🍎" "🐧") -return data; -``` - - 🍎 - -\#+ENDSRC Or previous-like example with dirs but without needing additional source block: - -```elisp -#+begin_src clojure :var data=(shell-command-to-string "ls -a ~") -;; all dotfiles -(require '[clojure.string :as str]) +# u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd) -(->> (str/split data #"\n") - (filter (partial re-find #"^\.*")) - (sort) - (str/join "\n")) -``` +**Votes** 10 -\#+ENDSRC +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/regob [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfskmro) @@ -2374,20 +2358,6 @@ return data; `C-x C-e` to edit current command line in bash which opens the line in emacs (maybe not emacs related but I found this recently useful when working in the terminal) -# u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb) - -**Votes** 9 - -[deleted] - - -# u/JDRiverRun [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) - -**Votes** 9 - -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/pt-guzzardo [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) **Votes** 9 @@ -2419,31 +2389,34 @@ When I'm in Vim, I've found it useful to sometimes split a buffer into two windo 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) +# u/lesliesrussell [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) **Votes** 9 -This makes stack-outputs of debug-buffers much more readable: +[transient map for movement](https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf) -```elisp -(setopt debugger-stack-frame-as-list 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\\~. +​ -# u/leothrix [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c) +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. -**Votes** 9 +​ -Need to remove an element from a list when you're tinkering with elisp? +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! -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 didn't want to drop code in the thread so i put it in a gist -```elisp -M-x remove-hook -``` +# u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_18mplfa/comment/t1_ke5xr5j) -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. +**Votes** 9 + +This makes stack-outputs of debug-buffers much more readable: + +```elisp +(setopt debugger-stack-frame-as-list t) +``` # u/Netherus [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8c4mz7) @@ -2453,32 +2426,41 @@ And you've got an interactive interface (using `completing-read`) for removing a 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. -# u/frosch03 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) +# u/gusbrs [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) **Votes** 9 -Very useful, but I keep forgetting it: - -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 +` +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/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv) +# u/BunnyLushington [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp) **Votes** 9 -I work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: +I found myself debugging [JWTs](https://jwt.io) earlier this week and whomped up a little function to decode them from a region into a help buffer. ```elisp -(defun default-to-main-project (dir) - (or dir *main-project-dir*)) - -(advice-add 'projectile-ensure-project :override #'default-to-main-project) - +(defun ii/decode-jwt (start end &optional jwt) + "Decode JWT in region and print to help buffer." + (interactive "r") + (let* ((tok (if jwt jwt + (buffer-substring start end))) + (data (s-split "\\." tok)) + (header (car data)) + (claims (cadr data))) +(with-temp-buffer + (insert (format "%s\n\n%s" + (base64-decode-string header t) + (base64-decode-string claims t))) + (json-pretty-print-buffer) + (with-output-to-temp-buffer "*JWT*" + (princ (buffer-string))))) + t) ``` -I lose some of the functionality of `projectile-ensure-project`, but I never used it anyway. +I'd forgotten about `with-output-to-temp-buffer` which is pretty handy. The `t` at the end is there just to suppress an overly large echo area message. + +(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/pathemata [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mpo5y) @@ -2993,6 +2975,63 @@ Each person gets a different colour to indicate the part of the file they’re e 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/fv\_\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe) + +**Votes** 8 + +C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ –force-with-lease~ by default while pushing in magit (P p) + + +# u/ilemming [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1) + +**Votes** 8 + +You know that you can use vars in org source blocks that inject some data, like: + +```elisp +#+begin_src bash :var token="bla-bla-bla" +echo ${token} +``` + + bla-bla-bla + +\#+ENDSRC That can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block. + +```elisp +#+name: dirs +#+begin_src bash :results silent +ls +``` + +```js +console.log(data) +``` + +\#+ENDSRC But did you know, you can also use elisp there? + +```elisp +#+begin_src js :var data=(if (featurep :system 'macos) "🍎" "🐧") +return data; +``` + + 🍎 + +\#+ENDSRC Or previous-like example with dirs but without needing additional source block: + +```elisp +#+begin_src clojure :var data=(shell-command-to-string "ls -a ~") +;; all dotfiles +(require '[clojure.string :as str]) + +(->> (str/split data #"\n") + (filter (partial re-find #"^\.*")) + (sort) + (str/join "\n")) +``` + +\#+ENDSRC + + # u/meedstrom [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro) **Votes** 8 @@ -3015,6 +3054,13 @@ But now you can just add a space after the opening paren `'(`. This is the new c ``` +# u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb) + +**Votes** 8 + +[deleted] + + # u/MotorMouth\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lg6q2rq) **Votes** 8 @@ -3022,18 +3068,18 @@ 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/AdjointFunctor [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx) +# u/JDRiverRun [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) **Votes** 8 -I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. +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/demosthenex [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) +# u/AdjointFunctor [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx) **Votes** 8 -M-x ielm Use the repl while learning elisp coding. I had no idea! +I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. # u/vjgoh [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_18149ql/comment/t1_kahspwz) @@ -3056,61 +3102,15 @@ Long story short, here's how you force `project` to find the actual project root I used to always get confused why people say that the default Emacs key bindings hurt their pinky's, but then I realized that I don't touch type and thus I don't have to stretch my fingers anywhere for the default key bindings. Ironically my ineptitude at typing has saved me from repetitive stress injuries. -# u/BunnyLushington [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp) - -**Votes** 8 - -I found myself debugging [JWTs](https://jwt.io) earlier this week and whomped up a little function to decode them from a region into a help buffer. - -```elisp -(defun ii/decode-jwt (start end &optional jwt) - "Decode JWT in region and print to help buffer." - (interactive "r") - (let* ((tok (if jwt jwt - (buffer-substring start end))) - (data (s-split "\\." tok)) - (header (car data)) - (claims (cadr data))) -(with-temp-buffer - (insert (format "%s\n\n%s" - (base64-decode-string header t) - (base64-decode-string claims t))) - (json-pretty-print-buffer) - (with-output-to-temp-buffer "*JWT*" - (princ (buffer-string))))) - t) -``` - -I'd forgotten about `with-output-to-temp-buffer` which is pretty handy. The `t` at the end is there just to suppress an overly large echo area message. - -(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) +# u/frosch03 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) **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. +Very useful, but I keep forgetting 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 +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 -` -```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))) -``` +And if you want to balance these two buffers again just use `C-x +` # u/w0ntfix [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9) diff --git a/out.org b/out.org index a603566..4f22cdb 100644 --- a/out.org +++ b/out.org @@ -1,12 +1,5 @@ -** u/TheDrownedKraken [[https://www.reddit.com/r/emacs/comments/t3_o68i0v/comment/t1_h2rdkkz][πŸ”—]] -*Votes* 37 - -Do you think it might be good to make this a little less frequently refreshed? There are usually some great tips that get lost to Reddit’s ephemerality pretty quickly. - -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* 36 +*Votes* 37 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -17,6 +10,13 @@ It's in the manual, and a basic little feature, but really handy. https://www.gn I guess the other tip is to read the manual. :) +** u/TheDrownedKraken [[https://www.reddit.com/r/emacs/comments/t3_o68i0v/comment/t1_h2rdkkz][πŸ”—]] +*Votes* 37 + +Do you think it might be good to make this a little less frequently refreshed? There are usually some great tips that get lost to Reddit’s ephemerality pretty quickly. + +I think monthly would be better, given the modest size of this subreddit. + ** u/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_10qo7vb/comment/t1_j6rmvvf][πŸ”—]] *Votes* 33 @@ -56,19 +56,8 @@ After years of using emacs, I wrote my second ever elisp function to open on git [removed] -** u/Gangsir [[https://www.reddit.com/r/emacs/comments/t3_pxqvtm/comment/t1_hepqmq1][πŸ”—]] -*Votes* 22 - -back-to-indentation. Before I found this function I would always do some awkward triple key combo like C-a M-f M-b. - -It's just bound to M-m. Jumps you right to the first non-white space character on the line. What's even spicier is that it works in reverse too - if you're at the front of the line it jumps you forward, if you're at the end or middle it jumps backward. - -It still works even on lines that aren't indented, same as C-a in that case. - -So useful, especially for resetting point during macros that need to start at the first char on the line. - ** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1c0gg7n/comment/t1_kywimnf][πŸ”—]] -*Votes* 21 +*Votes* 22 Yasnippet has the capability of surrounding. For example, if you have this C++ namespace snippet: @@ -86,6 +75,17 @@ Then if you bind ~(yas-expand-snippet (yas-lookup-snippet "namespace-surround")) https://i.redd.it/fbsbbr98smtc1.gif +** u/Gangsir [[https://www.reddit.com/r/emacs/comments/t3_pxqvtm/comment/t1_hepqmq1][πŸ”—]] +*Votes* 22 + +back-to-indentation. Before I found this function I would always do some awkward triple key combo like C-a M-f M-b. + +It's just bound to M-m. Jumps you right to the first non-white space character on the line. What's even spicier is that it works in reverse too - if you're at the front of the line it jumps you forward, if you're at the end or middle it jumps backward. + +It still works even on lines that aren't indented, same as C-a in that case. + +So useful, especially for resetting point during macros that need to start at the first char on the line. + ** u/howardthegeek [[https://www.reddit.com/r/emacs/comments/t3_xdw6ok/comment/t1_ioeh1ly][πŸ”—]] *Votes* 21 @@ -151,22 +151,16 @@ 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/vkazanov [[https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y][πŸ”—]] -*Votes* 18 +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][πŸ”—]] +*Votes* 19 -A dump of my Emacs-related principles after 18 years of tinkering: +~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. 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. +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~ -I am a beginner though, things might change. +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/WorldsEndless [[https://www.reddit.com/r/emacs/comments/t3_12rlq4a/comment/t1_jgwlxuw][πŸ”—]] *Votes* 18 @@ -185,16 +179,22 @@ 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. https://github.com/angrybacon/dotemacs -** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gktndf/comment/t1_lvojz57][πŸ”—]] -*Votes* 18 +** u/vkazanov [[https://www.reddit.com/r/emacs/comments/t3_1bdm6mc/comment/t1_kuo1f9y][πŸ”—]] +*Votes* 17 -~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): +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 [[https://github.com/vedang/pdf-tools][~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/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_vnals8/comment/t1_ie7p6ja][πŸ”—]] *Votes* 17 @@ -379,6 +379,19 @@ 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/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 @@ -443,29 +456,6 @@ 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 @@ -481,19 +471,6 @@ 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 @@ -596,6 +573,56 @@ 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][πŸ”—]] +*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~]] + +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/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 + + +#+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/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][πŸ”—]] *Votes* 13 @@ -1051,31 +1078,31 @@ 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][πŸ”—]] +** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][πŸ”—]] *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 started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: -\* ~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 +#+BEGIN_SRC elisp +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) -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): +#+END_SRC +A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and _finally_ was able to work it out after poring over the documentation for the ~org-capture-templates~ variable. It turns out the default "template" for the ~entry~ capture type is ~"* %?\n%a"~, where the code ~%a~ means "annotation," ie, a link to the file location. So I just had to change my definition to this: #+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))) - +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) #+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/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][πŸ”—]] +*Votes* 12 + +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/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][πŸ”—]] *Votes* 12 @@ -1231,68 +1258,54 @@ I used to use the which-key package to discover key bindings, but now have compl 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][πŸ”—]] +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][πŸ”—]] *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 +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 - (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))) + #+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][πŸ”—]] +** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][πŸ”—]] *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 - -I started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: +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 org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) - +(setq use-package-enable-imenu-support t) #+END_SRC -A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and _finally_ was able to work it out after poring over the documentation for the ~org-capture-templates~ variable. It turns out the default "template" for the ~entry~ capture type is ~"* %?\n%a"~, where the code ~%a~ means "annotation," ie, a link to the file location. So I just had to change my definition to this: -#+BEGIN_SRC elisp -(setq org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) -#+END_SRC +Combined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly. -** u/Usual_Office_1740 [[https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9][πŸ”—]] +** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][πŸ”—]] *Votes* 11 -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. +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. -** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][πŸ”—]] -*Votes* 11 +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. -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. +** u/Usual_Office_1740 [[https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9][πŸ”—]] +*Votes* 11 -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. +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][πŸ”—]] *Votes* 11 @@ -1308,6 +1321,19 @@ 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/leothrix [[https://www.reddit.com/r/emacs/comments/t3_17qh1hn/comment/t1_k8dlt4c][πŸ”—]] +*Votes* 11 + +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/tryptych [[https://www.reddit.com/r/emacs/comments/t3_w3gx6o/comment/t1_ih6ievs][πŸ”—]] *Votes* 11 @@ -1402,26 +1428,25 @@ 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/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 +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][πŸ”—]] +*Votes* 10 -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. +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/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][πŸ”—]] -*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. -One of my favourite tips for managing my init file is the ~imenu~ support in ~use-package~. It's turned off by default, though: +The installation is easy, you just need to hook it into ~org-mode~: #+BEGIN_SRC elisp -(setq use-package-enable-imenu-support t) + (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). -Combined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly. +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/winters_here [[https://www.reddit.com/r/emacs/comments/t3_1eaw1ia/comment/t1_leom8fv][πŸ”—]] *Votes* 10 @@ -1443,14 +1468,17 @@ 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/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][πŸ”—]] +** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][πŸ”—]] *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): +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. -https://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opinionated_porcelain/l2yi5tn/ +If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. -I assume the same trick applies to other mode-maps as well. +** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][πŸ”—]] +*Votes* 10 + +M-x ielm Use the repl while learning elisp coding. I had no idea! ** u/bopboa [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3][πŸ”—]] *Votes* 10 @@ -1474,23 +1502,6 @@ 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/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 @@ -1553,10 +1564,44 @@ E.g. capitalize or decapitalize the next word, increment number at point." #+END_SRC I bind it to ~M-c~. -** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][πŸ”—]] +** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][πŸ”—]] *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 work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: + +#+BEGIN_SRC elisp +(defun default-to-main-project (dir) + (or dir *main-project-dir*)) + +(advice-add 'projectile-ensure-project :override #'default-to-main-project) + +#+END_SRC +I lose some of the functionality of ~projectile-ensure-project~, but I never used it anyway. + +** 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 @@ -1996,6 +2041,11 @@ 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/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][πŸ”—]] +*Votes* 10 + +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][πŸ”—]] *Votes* 10 @@ -2034,98 +2084,16 @@ 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/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 - -C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ --force-with-lease~ by default while pushing in magit (P p) - -** u/ilemming [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1][πŸ”—]] -*Votes* 9 - -You know that you can use vars in org source blocks that inject some data, like: - -#+BEGIN_SRC elisp - #+begin_src bash :var token="bla-bla-bla" - echo ${token} - #+end_src - - #+RESULTS: - : bla-bla-bla - -#+END_SRC -That can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block. - -#+BEGIN_SRC elisp - #+name: dirs - #+begin_src bash :results silent - ls - #+end_src - - #+begin_src js :var data=dirs - console.log(data) - #+end_src - -#+END_SRC -But did you know, you can also use elisp there? - -#+BEGIN_SRC elisp - #+begin_src js :var data=(if (featurep :system 'macos) "🍎" "🐧") - return data; - #+end_src - - #+RESULTS: - : 🍎 - -#+END_SRC -Or previous-like example with dirs but without needing additional source block: - -#+BEGIN_SRC elisp -#+begin_src clojure :var data=(shell-command-to-string "ls -a ~") -;; all dotfiles -(require '[clojure.string :as str]) +** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd][πŸ”—]] +*Votes* 10 -(->> (str/split data #"\n") - (filter (partial re-find #"^\.*")) - (sort) - (str/join "\n")) -#+end_src -#+END_SRC +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/rego_b [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfskmro][πŸ”—]] *Votes* 9 ~C-x C-e~ to edit current command line in bash which opens the line in emacs (maybe not emacs related but I found this recently useful when working in the terminal) -** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb][πŸ”—]] -*Votes* 9 - -[deleted] - -** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][πŸ”—]] -*Votes* 9 - -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 @@ -2152,55 +2120,69 @@ When I'm in Vim, I've found it useful to sometimes split a buffer into two windo 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][πŸ”—]] +** u/lesliesrussell [[https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2][πŸ”—]] *Votes* 9 -This makes stack-outputs of debug-buffers much more readable: +[[https://gist.github.com/lesliesrussell/46302d413fcf49e9717eeea57fdadcbf][transient map for movement]] -#+BEGIN_SRC elisp -(setopt debugger-stack-frame-as-list t) -#+END_SRC +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\~. -** 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? +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. -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 +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/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_18mplfa/comment/t1_ke5xr5j][πŸ”—]] +*Votes* 9 +This makes stack-outputs of debug-buffers much more readable: + +#+BEGIN_SRC elisp +(setopt debugger-stack-frame-as-list t) #+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 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. -** u/frosch03 [[https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a][πŸ”—]] +** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][πŸ”—]] *Votes* 9 -Very useful, but I keep forgetting it: - -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 +~ +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/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][πŸ”—]] +** u/BunnyLushington [[https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp][πŸ”—]] *Votes* 9 -I work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: +I found myself debugging [[https://jwt.io][JWTs]] earlier this week and whomped up a little function to decode them from a region into a help buffer. #+BEGIN_SRC elisp -(defun default-to-main-project (dir) - (or dir *main-project-dir*)) +(defun ii/decode-jwt (start end &optional jwt) + "Decode JWT in region and print to help buffer." + (interactive "r") + (let* ((tok (if jwt jwt + (buffer-substring start end))) + (data (s-split "\\." tok)) + (header (car data)) + (claims (cadr data))) +(with-temp-buffer + (insert (format "%s\n\n%s" + (base64-decode-string header t) + (base64-decode-string claims t))) + (json-pretty-print-buffer) + (with-output-to-temp-buffer "*JWT*" + (princ (buffer-string))))) + t) +#+END_SRC -(advice-add 'projectile-ensure-project :override #'default-to-main-project) +I'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ at the end is there just to suppress an overly large echo area message. -#+END_SRC -I lose some of the functionality of ~projectile-ensure-project~, but I never used it anyway. +(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/pathemata [[https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mpo5y][πŸ”—]] *Votes* 9 @@ -2676,6 +2658,63 @@ https://imgur.com/a/zvfLpdH 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/fv__ [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe][πŸ”—]] +*Votes* 8 + +C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ --force-with-lease~ by default while pushing in magit (P p) + +** u/ilemming [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1][πŸ”—]] +*Votes* 8 + +You know that you can use vars in org source blocks that inject some data, like: + +#+BEGIN_SRC elisp + #+begin_src bash :var token="bla-bla-bla" + echo ${token} + #+end_src + + #+RESULTS: + : bla-bla-bla + +#+END_SRC +That can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block. + +#+BEGIN_SRC elisp + #+name: dirs + #+begin_src bash :results silent + ls + #+end_src + + #+begin_src js :var data=dirs + console.log(data) + #+end_src + +#+END_SRC +But did you know, you can also use elisp there? + +#+BEGIN_SRC elisp + #+begin_src js :var data=(if (featurep :system 'macos) "🍎" "🐧") + return data; + #+end_src + + #+RESULTS: + : 🍎 + +#+END_SRC +Or previous-like example with dirs but without needing additional source block: + +#+BEGIN_SRC elisp +#+begin_src clojure :var data=(shell-command-to-string "ls -a ~") +;; all dotfiles +(require '[clojure.string :as str]) + +(->> (str/split data #"\n") + (filter (partial re-find #"^\.*")) + (sort) + (str/join "\n")) +#+end_src +#+END_SRC + ** u/meedstrom [[https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro][πŸ”—]] *Votes* 8 @@ -2695,20 +2734,25 @@ But now you can just add a space after the opening paren ~'(~. This is the new :rab oof) #+END_SRC +** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb][πŸ”—]] +*Votes* 8 + +[deleted] + ** u/Motor_Mouth_ [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lg6q2rq][πŸ”—]] *Votes* 8 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/AdjointFunctor [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx][πŸ”—]] +** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][πŸ”—]] *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/ +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/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][πŸ”—]] +** u/AdjointFunctor [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx][πŸ”—]] *Votes* 8 -M-x ielm Use the repl while learning elisp coding. I had no idea! +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/vjgoh [[https://www.reddit.com/r/emacs/comments/t3_18149ql/comment/t1_kahspwz][πŸ”—]] *Votes* 8 @@ -2726,58 +2770,14 @@ Long story short, here's how you force ~project~ to find the actual project root I used to always get confused why people say that the default Emacs key bindings hurt their pinky's, but then I realized that I don't touch type and thus I don't have to stretch my fingers anywhere for the default key bindings. Ironically my ineptitude at typing has saved me from repetitive stress injuries. -** u/BunnyLushington [[https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp][πŸ”—]] -*Votes* 8 - -I found myself debugging [[https://jwt.io][JWTs]] earlier this week and whomped up a little function to decode them from a region into a help buffer. - -#+BEGIN_SRC elisp -(defun ii/decode-jwt (start end &optional jwt) - "Decode JWT in region and print to help buffer." - (interactive "r") - (let* ((tok (if jwt jwt - (buffer-substring start end))) - (data (s-split "\\." tok)) - (header (car data)) - (claims (cadr data))) -(with-temp-buffer - (insert (format "%s\n\n%s" - (base64-decode-string header t) - (base64-decode-string claims t))) - (json-pretty-print-buffer) - (with-output-to-temp-buffer "*JWT*" - (princ (buffer-string))))) - t) -#+END_SRC - -I'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ at the end is there just to suppress an overly large echo area message. - -(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][πŸ”—]] +** u/frosch03 [[https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a][πŸ”—]] *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. +Very useful, but I keep forgetting 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 +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 -~ -#+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 +And if you want to balance these two buffers again just use ~C-x +~ ** u/w0ntfix [[https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9][πŸ”—]] *Votes* 8 diff --git a/out_by_year.md b/out_by_year.md index cd9dd08..9e896af 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** 36 +**Votes** 37 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -31,7 +31,7 @@ I guess the other tip is to read the manual. :) ### u/geza42 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1c0gg7n/comment/t1_kywimnf) -**Votes** 21 +**Votes** 22 Yasnippet has the capability of surrounding. For example, if you have this C++ namespace snippet: @@ -51,9 +51,22 @@ 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** 18 +**Votes** 17 A dump of my Emacs-related principles after 18 years of tinkering: @@ -70,22 +83,9 @@ 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** 14 +**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: @@ -106,30 +106,63 @@ But regardless what you are using, chances are there already is a suitable `*-po ``` -### u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) +### u/mlk [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9) -**Votes** 12 +**Votes** 13 -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 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 -\\\* `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 +```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) +``` -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/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9) + +**Votes** 12 + +I started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: ```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))) +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) ``` -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`. +A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and finally was able to work it out after poring over the documentation for the `org-capture-templates` variable. It turns out the default "template" for the `entry` capture type is `"* %?\n%a"`, where the code `%a` means "annotation," ie, a link to the file location. So I just had to change my definition to this: + +```elisp +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) +``` + + +### u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) + +**Votes** 12 + +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 assume the same trick applies to other mode-maps as well. ### u/remillard [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he) @@ -163,77 +196,59 @@ I used to use the which-key package to discover key bindings, but now have compl 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) +### u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6) **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) -``` +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 -### u/thetemp\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) +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): -**Votes** 11 +```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 [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. +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/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9) +### u/fuzzbomb23 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7) **Votes** 11 -I started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: +One of my favourite tips for managing my init file is the `imenu` support in `use-package`. It's turned off by default, though: ```elisp -(setq org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) - +(setq use-package-enable-imenu-support t) ``` -A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and finally was able to work it out after poring over the documentation for the `org-capture-templates` variable. It turns out the default "template" for the `entry` capture type is `"* %?\n%a"`, where the code `%a` means "annotation," ie, a link to the file location. So I just had to change my definition to this: - -```elisp -(setq org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) -``` +Combined with a nice imenu UI (`consult-imenu` and Vertico, say) you can navigate your init file really quickly. -### u/UsualOffice1740 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9) +### u/thetemp\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy) **Votes** 11 -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. +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/saltwaterflyguy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) -**Votes** 11 +### u/UsualOffice1740 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9) -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. +**Votes** 11 -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. +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) @@ -254,31 +269,26 @@ 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/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/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9) +**Votes** 10 -### u/fuzzbomb23 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7) +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`: -**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. -One of my favourite tips for managing my init file is the `imenu` support in `use-package`. It's turned off by default, though: +The installation is easy, you just need to hook it into `org-mode`: ```elisp -(setq use-package-enable-imenu-support t) +(use-package org-pdftools + :after (org pdf-tools) + :hook (org-mode . org-pdftools-setup-link)) + ``` -Combined with a nice imenu UI (`consult-imenu` and Vertico, say) you can navigate your init file really quickly. +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/wintershere [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eaw1ia/comment/t1_leom8fv) @@ -305,15 +315,20 @@ 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/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q) +### u/saltwaterflyguy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8) **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): +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. -I assume the same trick applies to other mode-maps as well. + +### u/demosthenex [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) + +**Votes** 10 + +M-x ielm Use the repl while learning elisp coding. I had no idea! ### u/bopboa [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3) @@ -343,25 +358,6 @@ 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/lesliesrussell [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) - -**Votes** 10 - -[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/camelcaset [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_18xebux/comment/t1_kgce54q) **Votes** 10 @@ -390,6 +386,13 @@ I created this file and now Emacs keybindings work everywhere: You can read more here: +### u/konrad1977 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i) + +**Votes** 10 + +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) **Votes** 10 @@ -432,142 +435,132 @@ toolbar { 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 -(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_1hgx486/comment/t1_m2mx3xd) -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** 10 -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. +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/fv\_\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe) +### u/regob [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfskmro) **Votes** 9 -C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ –force-with-lease~ by default while pushing in magit (P p) +`C-x C-e` to edit current command line in bash which opens the line in emacs (maybe not emacs related but I found this recently useful when working in the terminal) -### u/ilemming [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1) +### u/pt-guzzardo [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) **Votes** 9 -You know that you can use vars in org source blocks that inject some data, like: - -```elisp -#+begin_src bash :var token="bla-bla-bla" -echo ${token} -``` - - bla-bla-bla - -\#+ENDSRC That can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block. - ```elisp -#+name: dirs -#+begin_src bash :results silent -ls -``` +(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)))) -```js -console.log(data) ``` -\#+ENDSRC But did you know, you can also use elisp there? +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. -```elisp -#+begin_src js :var data=(if (featurep :system 'macos) "🍎" "🐧") -return data; -``` - 🍎 +### u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp) -\#+ENDSRC Or previous-like example with dirs but without needing additional source block: +**Votes** 9 -```elisp -#+begin_src clojure :var data=(shell-command-to-string "ls -a ~") -;; all dotfiles -(require '[clojure.string :as str]) +Many of you probably know of this, but I found "indirect buffers" useful. -(->> (str/split data #"\n") - (filter (partial re-find #"^\.*")) - (sort) - (str/join "\n")) -``` +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. -\#+ENDSRC +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/regob [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfskmro) +### u/lesliesrussell [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_198rnkj/comment/t1_kibmgv2) **Votes** 9 -`C-x C-e` to edit current command line in bash which opens the line in emacs (maybe not emacs related but I found this recently useful when working in the terminal) +[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\\~. -### u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb) +​ -**Votes** 9 +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. -[deleted] +​ + +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/JDRiverRun [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) + +### u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu) **Votes** 9 -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. +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/pt-guzzardo [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx) +### u/fv\_\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe) -**Votes** 9 +**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)))) +C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ –force-with-lease~ by default while pushing in magit (P p) + + +### u/ilemming [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1) + +**Votes** 8 + +You know that you can use vars in org source blocks that inject some data, like: +```elisp +#+begin_src bash :var token="bla-bla-bla" +echo ${token} ``` -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. + bla-bla-bla +\#+ENDSRC That can be used to pass data from one block to another, right? So if you need to calculate something based on the result of another block, you just need a named block. -### u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kpct4cp) +```elisp +#+name: dirs +#+begin_src bash :results silent +ls +``` -**Votes** 9 +```js +console.log(data) +``` -Many of you probably know of this, but I found "indirect buffers" useful. +\#+ENDSRC But did you know, you can also use elisp there? -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 +#+begin_src js :var data=(if (featurep :system 'macos) "🍎" "🐧") +return data; +``` -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. + 🍎 +\#+ENDSRC Or previous-like example with dirs but without needing additional source block: -### u/ImJustPassinBy [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu) +```elisp +#+begin_src clojure :var data=(shell-command-to-string "ls -a ~") +;; all dotfiles +(require '[clojure.string :as str]) -**Votes** 9 +(->> (str/split data #"\n") + (filter (partial re-find #"^\.*")) + (sort) + (str/join "\n")) +``` -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. +\#+ENDSRC ### u/meedstrom [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1fe504e/comment/t1_lmzbyro) @@ -592,6 +585,13 @@ But now you can just add a space after the opening paren `'(`. This is the new c ``` +### u/[deleted] [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb) + +**Votes** 8 + +[deleted] + + ### u/MotorMouth\_ [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lg6q2rq) **Votes** 8 @@ -599,18 +599,18 @@ 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/AdjointFunctor [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx) +### u/JDRiverRun [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3) **Votes** 8 -I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. +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/demosthenex [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6) +### u/AdjointFunctor [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx) **Votes** 8 -M-x ielm Use the repl while learning elisp coding. I had no idea! +I (re) discovered rectangle mode recently. Very useful when deleting lots of indents. C-x spc then make the region. ### u/IcyThought [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_1aw6xkc/comment/t1_kriu3ye) @@ -720,6 +720,21 @@ But this week I discovered `ffap-bindings`. This function replaces some key bind `(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/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/alvarogonzalezs [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l) **Votes** 14 @@ -738,21 +753,6 @@ 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/leothrix [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z) **Votes** 13 @@ -841,6 +841,22 @@ 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) + +**Votes** 11 + +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: + +```elisp +M-x remove-hook + +``` + +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/PriorOutcome [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw) **Votes** 10 @@ -881,11 +897,48 @@ E.g. capitalize or decapitalize the next word, increment number at point." I bind it to `M-c`. -### u/gusbrs [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) +### u/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv) **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 work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: + +```elisp +(defun default-to-main-project (dir) + (or dir *main-project-dir*)) + +(advice-add 'projectile-ensure-project :override #'default-to-main-project) + +``` + +I lose some of the functionality of `projectile-ensure-project`, but I never used it anyway. + + +### 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) @@ -954,22 +1007,6 @@ This makes stack-outputs of debug-buffers much more readable: ``` -### 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: - -```elisp -M-x remove-hook - -``` - -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 @@ -977,32 +1014,41 @@ And you've got an interactive interface (using `completing-read`) for removing a 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. -### u/frosch03 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) +### u/gusbrs [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts) **Votes** 9 -Very useful, but I keep forgetting it: - -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 +` +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/sauntcartas [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv) +### u/BunnyLushington [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp) **Votes** 9 -I work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: +I found myself debugging [JWTs](https://jwt.io) earlier this week and whomped up a little function to decode them from a region into a help buffer. ```elisp -(defun default-to-main-project (dir) - (or dir *main-project-dir*)) - -(advice-add 'projectile-ensure-project :override #'default-to-main-project) - +(defun ii/decode-jwt (start end &optional jwt) + "Decode JWT in region and print to help buffer." + (interactive "r") + (let* ((tok (if jwt jwt + (buffer-substring start end))) + (data (s-split "\\." tok)) + (header (car data)) + (claims (cadr data))) +(with-temp-buffer + (insert (format "%s\n\n%s" + (base64-decode-string header t) + (base64-decode-string claims t))) + (json-pretty-print-buffer) + (with-output-to-temp-buffer "*JWT*" + (princ (buffer-string))))) + t) ``` -I lose some of the functionality of `projectile-ensure-project`, but I never used it anyway. +I'd forgotten about `with-output-to-temp-buffer` which is pretty handy. The `t` at the end is there just to suppress an overly large echo area message. + +(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/pathemata [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mpo5y) @@ -1034,61 +1080,15 @@ Long story short, here's how you force `project` to find the actual project root I used to always get confused why people say that the default Emacs key bindings hurt their pinky's, but then I realized that I don't touch type and thus I don't have to stretch my fingers anywhere for the default key bindings. Ironically my ineptitude at typing has saved me from repetitive stress injuries. -### u/BunnyLushington [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp) - -**Votes** 8 - -I found myself debugging [JWTs](https://jwt.io) earlier this week and whomped up a little function to decode them from a region into a help buffer. - -```elisp -(defun ii/decode-jwt (start end &optional jwt) - "Decode JWT in region and print to help buffer." - (interactive "r") - (let* ((tok (if jwt jwt - (buffer-substring start end))) - (data (s-split "\\." tok)) - (header (car data)) - (claims (cadr data))) -(with-temp-buffer - (insert (format "%s\n\n%s" - (base64-decode-string header t) - (base64-decode-string claims t))) - (json-pretty-print-buffer) - (with-output-to-temp-buffer "*JWT*" - (princ (buffer-string))))) - t) -``` - -I'd forgotten about `with-output-to-temp-buffer` which is pretty handy. The `t` at the end is there just to suppress an overly large echo area message. - -(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) +### u/frosch03 [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a) **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. +Very useful, but I keep forgetting 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 +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 -` -```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))) -``` +And if you want to balance these two buffers again just use `C-x +` ### u/w0ntfix [πŸ”—](https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9) diff --git a/out_by_year.org b/out_by_year.org index 4c08560..95cdacb 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* 36 +*Votes* 37 Nothing revolutionary (and veterans will already know this), but a nice little function for splitting out text to a separate file: @@ -32,7 +32,7 @@ It's in the manual, and a basic little feature, but really handy. https://www.gn I guess the other tip is to read the manual. :) *** u/geza42 [[https://www.reddit.com/r/emacs/comments/t3_1c0gg7n/comment/t1_kywimnf][πŸ”—]] -*Votes* 21 +*Votes* 22 Yasnippet has the capability of surrounding. For example, if you have this C++ namespace snippet: @@ -50,8 +50,19 @@ 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* 18 +*Votes* 17 A dump of my Emacs-related principles after 18 years of tinkering: @@ -67,19 +78,8 @@ 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* 14 +*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: @@ -101,31 +101,58 @@ 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 +*** u/mlk [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_lnqelw9][πŸ”—]] +*Votes* 13 -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 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 -\* ~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 + (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/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][πŸ”—]] +*Votes* 12 + +I started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: #+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))) +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) #+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~. +A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and _finally_ was able to work it out after poring over the documentation for the ~org-capture-templates~ variable. It turns out the default "template" for the ~entry~ capture type is ~"* %?\n%a"~, where the code ~%a~ means "annotation," ie, a link to the file location. So I just had to change my definition to this: + +#+BEGIN_SRC elisp +(setq org-capture-templates + '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) +#+END_SRC + +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][πŸ”—]] +*Votes* 12 + +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/remillard [[https://www.reddit.com/r/emacs/comments/t3_1cbsvxd/comment/t1_l11l7he][πŸ”—]] *Votes* 12 @@ -152,68 +179,54 @@ I used to use the which-key package to discover key bindings, but now have compl 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][πŸ”—]] +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1f8nxb5/comment/t1_llfyzu6][πŸ”—]] *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 - +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: -#+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 +\* ~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 -*** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][πŸ”—]] -*Votes* 11 +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): -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. +#+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 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. +#+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/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_1djdync/comment/t1_l9cmdp9][πŸ”—]] +*** u/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][πŸ”—]] *Votes* 11 -I started using org-capture when I started my current job several years ago. I recorded my daily activities using this template: +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 org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org")))) - +(setq use-package-enable-imenu-support t) #+END_SRC -A minor annoyance was that an unwanted link to whatever file location I happened to be in when I invoked org-capture was stored along with my log entry. I made occasional desultory efforts over the years to remove it, but I just couldn't figure it out. I recently made a more concerted effort and _finally_ was able to work it out after poring over the documentation for the ~org-capture-templates~ variable. It turns out the default "template" for the ~entry~ capture type is ~"* %?\n%a"~, where the code ~%a~ means "annotation," ie, a link to the file location. So I just had to change my definition to this: -#+BEGIN_SRC elisp -(setq org-capture-templates - '(("d" "Done" entry (file+olp+datetree "~/org/done.org") "* %?"))) -#+END_SRC +Combined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly. -*** u/Usual_Office_1740 [[https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9][πŸ”—]] +*** u/thetemp_ [[https://www.reddit.com/r/emacs/comments/t3_1e5ctk2/comment/t1_ldsl3vy][πŸ”—]] *Votes* 11 -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. +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. -*** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][πŸ”—]] -*Votes* 11 +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. -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. +*** u/Usual_Office_1740 [[https://www.reddit.com/r/emacs/comments/t3_1d371oz/comment/t1_l687lg9][πŸ”—]] +*Votes* 11 -If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. +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][πŸ”—]] *Votes* 11 @@ -229,26 +242,25 @@ 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/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 +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][πŸ”—]] +*Votes* 10 -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. +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/fuzzbomb23 [[https://www.reddit.com/r/emacs/comments/t3_1f34tdh/comment/t1_lkrhqf7][πŸ”—]] -*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. -One of my favourite tips for managing my init file is the ~imenu~ support in ~use-package~. It's turned off by default, though: +The installation is easy, you just need to hook it into ~org-mode~: #+BEGIN_SRC elisp -(setq use-package-enable-imenu-support t) + (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). -Combined with a nice imenu UI (~consult-imenu~ and Vertico, say) you can navigate your init file really quickly. +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/winters_here [[https://www.reddit.com/r/emacs/comments/t3_1eaw1ia/comment/t1_leom8fv][πŸ”—]] *Votes* 10 @@ -270,14 +282,17 @@ 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/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l33y04q][πŸ”—]] +*** u/saltwaterflyguy [[https://www.reddit.com/r/emacs/comments/t3_1bun8ky/comment/t1_kxur0j8][πŸ”—]] *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): +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. -https://www.reddit.com/r/emacs/comments/1clvkfe/announcing_casual_dired_an_opinionated_porcelain/l2yi5tn/ +If you are new to Emacs you will get so many answers to your questions by getting to know all of the describe functions. -I assume the same trick applies to other mode-maps as well. +*** u/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][πŸ”—]] +*Votes* 10 + +M-x ielm Use the repl while learning elisp coding. I had no idea! *** u/bopboa [[https://www.reddit.com/r/emacs/comments/t3_1aky57w/comment/t1_kphrvz3][πŸ”—]] *Votes* 10 @@ -301,23 +316,6 @@ 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/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 @@ -343,6 +341,11 @@ 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/konrad1977 [[https://www.reddit.com/r/emacs/comments/t3_1gq86x9/comment/t1_lx7y88i][πŸ”—]] +*Votes* 10 + +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][πŸ”—]] *Votes* 10 @@ -381,33 +384,71 @@ 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/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gfhkdg/comment/t1_lui5ao9][πŸ”—]] +*** u/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1hgx486/comment/t1_m2mx3xd][πŸ”—]] +*Votes* 10 + +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/rego_b [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfskmro][πŸ”—]] *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~: +~C-x C-e~ to edit current command line in bash which opens the line in emacs (maybe not emacs related but I found this recently useful when working in the terminal) -\* 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. +*** u/pt-guzzardo [[https://www.reddit.com/r/emacs/comments/t3_1chgsxe/comment/t1_l2cv5cx][πŸ”—]] +*Votes* 9 + +#+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. + +*** 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. + +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/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. -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)) +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! -#+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). +I didn't want to drop code in the thread so i put it in a gist -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/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][πŸ”—]] +*Votes* 9 + +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/fv__ [[https://www.reddit.com/r/emacs/comments/t3_1fzmgwb/comment/t1_lr5ceqe][πŸ”—]] -*Votes* 9 +*Votes* 8 C-x in a transient popup shows menu to save selected options e.g., it can be used to select ~ --force-with-lease~ by default while pushing in magit (P p) *** u/ilemming [[https://www.reddit.com/r/emacs/comments/t3_1fjnqgy/comment/t1_ls4kmt1][πŸ”—]] -*Votes* 9 +*Votes* 8 You know that you can use vars in org source blocks that inject some data, like: @@ -458,52 +499,6 @@ Or previous-like example with dirs but without needing additional source block: #+end_src #+END_SRC -*** u/rego_b [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfskmro][πŸ”—]] -*Votes* 9 - -~C-x C-e~ to edit current command line in bash which opens the line in emacs (maybe not emacs related but I found this recently useful when working in the terminal) - -*** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb][πŸ”—]] -*Votes* 9 - -[deleted] - -*** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][πŸ”—]] -*Votes* 9 - -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 - -#+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. - -*** 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. - -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/ImJustPassinBy [[https://www.reddit.com/r/emacs/comments/t3_1gvkske/comment/t1_lyptzyu][πŸ”—]] -*Votes* 9 - -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 @@ -523,20 +518,25 @@ But now you can just add a space after the opening paren ~'(~. This is the new :rab oof) #+END_SRC +*** u/[deleted] [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lfsffnb][πŸ”—]] +*Votes* 8 + +[deleted] + *** u/Motor_Mouth_ [[https://www.reddit.com/r/emacs/comments/t3_1eghspj/comment/t1_lg6q2rq][πŸ”—]] *Votes* 8 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/AdjointFunctor [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx][πŸ”—]] +*** u/JDRiverRun [[https://www.reddit.com/r/emacs/comments/t3_1de1hkf/comment/t1_l8d30q3][πŸ”—]] *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/ +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/demosthenex [[https://www.reddit.com/r/emacs/comments/t3_1b7uj43/comment/t1_ktogga6][πŸ”—]] +*** u/AdjointFunctor [[https://www.reddit.com/r/emacs/comments/t3_1cmzd47/comment/t1_l359pqx][πŸ”—]] *Votes* 8 -M-x ielm Use the repl while learning elisp coding. I had no idea! +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/Icy_Thought [[https://www.reddit.com/r/emacs/comments/t3_1aw6xkc/comment/t1_kriu3ye][πŸ”—]] *Votes* 8 @@ -623,6 +623,19 @@ But this week I discovered ~ffap-bindings~. This function replaces some key bind ~(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/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/alvarogonzalezs [[https://www.reddit.com/r/emacs/comments/t3_16tes2a/comment/t1_k2gb81l][πŸ”—]] *Votes* 14 @@ -638,19 +651,6 @@ 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/leothrix [[https://www.reddit.com/r/emacs/comments/t3_13jvhp7/comment/t1_jl5zu6z][πŸ”—]] *Votes* 13 @@ -727,6 +727,19 @@ 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][πŸ”—]] +*Votes* 11 + +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/PriorOutcome [[https://www.reddit.com/r/emacs/comments/t3_15sjm3k/comment/t1_jwff8bw][πŸ”—]] *Votes* 10 @@ -764,10 +777,44 @@ E.g. capitalize or decapitalize the next word, increment number at point." #+END_SRC I bind it to ~M-c~. -*** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][πŸ”—]] +*** u/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][πŸ”—]] *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 work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: + +#+BEGIN_SRC elisp +(defun default-to-main-project (dir) + (or dir *main-project-dir*)) + +(advice-add 'projectile-ensure-project :override #'default-to-main-project) + +#+END_SRC +I lose some of the functionality of ~projectile-ensure-project~, but I never used it anyway. + +*** 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 @@ -825,46 +872,43 @@ 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 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. -*** u/frosch03 [[https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a][πŸ”—]] +*** u/gusbrs [[https://www.reddit.com/r/emacs/comments/t3_14l3jn8/comment/t1_jpwn2ts][πŸ”—]] *Votes* 9 -Very useful, but I keep forgetting it: - -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 +~ +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/sauntcartas [[https://www.reddit.com/r/emacs/comments/t3_12cd23k/comment/t1_jf3ohpv][πŸ”—]] +*** u/BunnyLushington [[https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp][πŸ”—]] *Votes* 9 -I work with multiple Git repositories in my day job, but one in particular occupies 95% of my time. I've often wished I could set up Projectile so that if I run one of its commands while not in any repo, it will behave as if I'd changed to that main repo first. I couldn't find a built-in way to do that, but got the effect I wanted with some advice: +I found myself debugging [[https://jwt.io][JWTs]] earlier this week and whomped up a little function to decode them from a region into a help buffer. #+BEGIN_SRC elisp -(defun default-to-main-project (dir) - (or dir *main-project-dir*)) +(defun ii/decode-jwt (start end &optional jwt) + "Decode JWT in region and print to help buffer." + (interactive "r") + (let* ((tok (if jwt jwt + (buffer-substring start end))) + (data (s-split "\\." tok)) + (header (car data)) + (claims (cadr data))) +(with-temp-buffer + (insert (format "%s\n\n%s" + (base64-decode-string header t) + (base64-decode-string claims t))) + (json-pretty-print-buffer) + (with-output-to-temp-buffer "*JWT*" + (princ (buffer-string))))) + t) +#+END_SRC -(advice-add 'projectile-ensure-project :override #'default-to-main-project) +I'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ at the end is there just to suppress an overly large echo area message. -#+END_SRC -I lose some of the functionality of ~projectile-ensure-project~, but I never used it anyway. +(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/pathemata [[https://www.reddit.com/r/emacs/comments/t3_112t0uo/comment/t1_j8mpo5y][πŸ”—]] *Votes* 9 @@ -889,58 +933,14 @@ Long story short, here's how you force ~project~ to find the actual project root I used to always get confused why people say that the default Emacs key bindings hurt their pinky's, but then I realized that I don't touch type and thus I don't have to stretch my fingers anywhere for the default key bindings. Ironically my ineptitude at typing has saved me from repetitive stress injuries. -*** u/BunnyLushington [[https://www.reddit.com/r/emacs/comments/t3_12zaqju/comment/t1_jhrzybp][πŸ”—]] -*Votes* 8 - -I found myself debugging [[https://jwt.io][JWTs]] earlier this week and whomped up a little function to decode them from a region into a help buffer. - -#+BEGIN_SRC elisp -(defun ii/decode-jwt (start end &optional jwt) - "Decode JWT in region and print to help buffer." - (interactive "r") - (let* ((tok (if jwt jwt - (buffer-substring start end))) - (data (s-split "\\." tok)) - (header (car data)) - (claims (cadr data))) -(with-temp-buffer - (insert (format "%s\n\n%s" - (base64-decode-string header t) - (base64-decode-string claims t))) - (json-pretty-print-buffer) - (with-output-to-temp-buffer "*JWT*" - (princ (buffer-string))))) - t) -#+END_SRC - -I'd forgotten about ~with-output-to-temp-buffer~ which is pretty handy. The ~t~ at the end is there just to suppress an overly large echo area message. - -(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][πŸ”—]] +*** u/frosch03 [[https://www.reddit.com/r/emacs/comments/t3_15yxdz3/comment/t1_jxekm3a][πŸ”—]] *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. +Very useful, but I keep forgetting 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 +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 -~ -#+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 +And if you want to balance these two buffers again just use ~C-x +~ *** u/w0ntfix [[https://www.reddit.com/r/emacs/comments/t3_11ey9ft/comment/t1_jajfxc9][πŸ”—]] *Votes* 8