reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-02-02 08:15
This is a thread for smaller, miscellaneous items that might not warrant a full post on their own. [See this search for previous "Weekly Tips, Tricks, &c." Threads.](https://www.reddit.com/r/emacs/search?q=Weekly+tips&restrict_sr=on&sort=new&t=all) Don't feel constrained in regards to what you post, just keep your post vaguely, generally on the topic of emacs.
Jack-o-tall-tales · 2022-02-02 12:47
Is there a way to ensure that an org export filter will take effect for some latex classes, but not others? My personal class and beamer both define an `example` environment, which I want to use for exporting `#+EXAMPLE` blocks, but most other classes don't, so for them I want to leave the behaviour as its default. Note that I don't think checking the keyword `#+LATEX_CLASS` is enough, because I use `org-beamer-mode`, which makes beamer export (with a `beamer` class) available even when this keyword is not explicitly set. Any ideas appreciated.
[deleted] · 2022-02-02 13:19
[deleted]
Hastrack · 2022-02-02 14:32
Simple function to extract archives in `dired` instead of opening in a buffer, it's a good template to other uses like converting a .mp3 file to .opus when opened (defun dired-find-file () "Replace current dired buffer with file buffer or open it externally if needed." (interactive) (let* ((path (dired-get-file-for-visit)) (file (file-name-nondirectory path)) (ext (file-name-extension file))) (pcase ext ((or "bz" "bz2" "tbz" "tbz2" "gz" "tgz" "xz") (progn (message "Extracting %s..." file) (call-process-shell-command (format "tar xfv \"%s\" &" path)))) ((or "zip" "7z" "rar") (progn (message "Extracting %s..." file) (call-process-shell-command (format "7z x \"%s\" &" path)))) (_ (find-alternate-file path)))))
emacsomancer · 2022-02-02 15:54
query: is there a way to have `pdf-tools` rebuild `epdfinfo` automatically without user intervention? I end up having to run the daemon manually so that I can hit `y` when it asks `Need to (re)build the epdfinfo program, do it now ? (y or n)`. I don't see any customisation to enable auto-building.
_viz_ · 2022-02-02 17:00
(pdf-tools-install 'no-query) This is what I have in my init file, (straight-use-package '(pdf-tools :type git :host github :repo "vedang/pdf-tools")) (pdf-tools-install 'no-query)
takeonrules · 2022-02-02 17:21
Hi all, I'm currently exploring moving my emacs config to a literate format. One thing I noticed is that while editing with a `src` block, I don't have the full `emacs-lisp` mode behavior. I'm wondering if there's any help to be had? What I was initially thinking is "What if I'm in a `src` block, I invoke a function which opens a new buffer with the contents of the source block, the major-mode informed by the `src` block. Then when I'm done (`C-c C-c` or such) it writes the content back to the original location." Do you folks know if that exists? I'm aware of https://github.com/xenodium/company-org-block which is for initial editing.
_viz_ · 2022-02-02 17:31
`C-c '`?
takeonrules · 2022-02-02 17:47
Why yes that does the trick. Thank you so much.
sierrawhiskeyfoxtrot · 2022-02-02 17:54
If you use [dired hacks](https://github.com/Fuco1/dired-hacks), you can get this without having to directly modify `dired-find-file`. You'd need to enable the `dired-open` part, and then could add functions to `dired-open-extensions-elisp`. As a bonus, there would be less that you have to write. I'd also recommend using `call-process` directly to customize the name of the buffer the output goes to.
Hastrack · 2022-02-02 17:59
>dired-find-file Thanks, but I directly modify `dired-find-file` because I have other custom functions for dired, so it's easier that way. >I'd also recommend using call-process directly to customize the name of the buffer the output goes to. Actually, I don't use `call-process` to avoid an output buffer
ground_ginger · 2022-02-02 18:53
Question: Is there a way to run a fully interactive zsh shell in org-babel? I don't need to actually interact with it, but I'd like features like history expansion to work. The purpose of this is to create a personal reference that explains these features. I've tried setting the \`:shebang\` header arg to \`zsh --interactive\`. This still doesn't enable the features I'm looking for. I'm also aware of ob-screen and ob-tmux. I've not tried those because my impression is that they do not capture the output of the source blocks. I imagine zsh must need an actual terminal for it to enable these features. Is there something for org-babel that might work with emacs' term or ansi-term?
SamTheComputerSlayer · 2022-02-02 19:13
Just figured this out, maybe a bit of a hack... In flyspell, I was annoyed I had to use mouse-2 when I wanted to correct a word, and I didn't want to sacrifice a major-mode keybinding to do it from the keyboard. But flyspell actually creates an overlay for misspelled words and attaches a keymap to it, which you can do I just realized- very cool. So I just bound `flyspell-correct-at-point` to "<return>" in the `flyspell-mouse-map`, and now return corrects words when my cursor is on a misspelled word! But the fact you can attach keymaps to overlays just seems so useful, will definitely use in the future.
kromobrn · 2022-02-02 20:25
Any built-in function to create an org tree out of indented text? E.g. transform a region like this: ``` Item A Item A.1 Item A.2 Item B Item B.1 Item B.2 ``` To this: ``` * Item A ** Item A.1 ** Item A.2 * Item B ** Item B.1 ** Item B.2 ``` I can easily hack my way to it, just found it weird not having anything built in for this.
Hammar_Morty · 2022-02-03 05:40
Think `:session` is what you are looking for.
Hammar_Morty · 2022-02-03 06:08
You want to run `org-toggle-item` `C-c -` to turn it into a list then run `org-toggle-heading` `C-c *` to turn them into headings. for some reason it does not preserve the sub sections running `org-toggle-heading` directly.
h-m-b-tu · 2022-02-03 08:26
There are lots of `org-export-filter-...-functions` variables where you can add functions to, which can change the output of an export filter. Those functions receive three arguments: The transcoded data, the export backend and the communication channel. Test for `(org-export-derived-backend-p backend 'latex)` and `(plist-get info :latex-class)` (which is the name of one of the `org-latex-classes`) in your function to conditionally alter the `data` string.
ground_ginger · 2022-02-03 14:12
Thanks for the reply. I gave this a shot: #+BEGIN_SRC shell :output results :session zsh-reference print 'First Command' print !?pr? #+END_SRC Unfortunately it produces no result block and flashes 'No History' in the minibuffer. I'm fiddling around with the zsh/zpty module. I can get an interactive zsh shell (with history expansion) running attached to one of these ptys, but it will take some work on my part to make it usable as a straightforward SRC block.
kromobrn · 2022-02-03 16:08
This does the trick, thanks!
Hammar_Morty · 2022-02-03 16:53
zsh sessions are freezing my Emacs. I think because of my prompt but have you tried p modifier `!?pr?:p` from [https://zsh.sourceforge.io/Doc/Release/Expansion.html](https://zsh.sourceforge.io/Doc/Release/Expansion.html) ?
trae · 2022-02-03 17:15
Hey folks, For writing code; I find myself constantly switching between `source.el` and `test-source.el`. Projectile has `projectile-find-test-file`, but it still makes me select the test from a completion list. Is there a faster way of doing this without manual hacks?
zhyang11 · 2022-02-03 17:54
I have this put into my `tty-setup-hook` for [CSI u](https://iterm2.com/documentation-csiu.html) style key encoding in the terminal: ``` (cl-loop for c from ?! to ?~ do (let* ((s (format "%d" c)) (spaced (replace-regexp-in-string "\\([0-9]\\)" "\\1 " s))) (cl-loop for b in '(("5" . "C-") ("7" . "C-M-")) do (define-key input-decode-map (kbd (concat "M-[ " spaced "; " (car b) " u")) (kbd (concat (cdr b) (char-to-string c))))))) ``` This is apparently not comprehensive but I could use some of the non-standard keys like `C-.` from the terminal, with a bit of tweak in the terminal side. I wish someone with more knowledge about encoding can do this properly and wrap it into a package. I mean, neovim already has it so...
ground_ginger · 2022-02-03 20:10
I see no change in behavior with the `:p` modifier. I'm poking around and learning some interesting things, but nothing that leads me to info that I think would be helpful (or that I could even explain correctly). I'll keep hacking at it. If I come up with anything useful I'll post it to a future thread. Thanks again.
crawsphi · 2022-02-04 20:28
Have a look at `ff-find-other-file` and its associated settings, like `ff-other-file-alist`. For example, the reply here: https://stackoverflow.com/questions/10437377/can-i-customize-ff-find-other-file-to-switch-between-tests-and-implementations
algalgal · 2022-02-05 16:58
This is interesting. Have you found many terminal emulators that support CSI u?
paretoOptimalDev · 2022-02-05 17:30
Do session headers somehow change or add to autocomplete sources? I don't think they do? If so, I've been missing out.
paretoOptimalDev · 2022-02-05 17:32
If you want it without opening the external buffer I know lsp-mode does some magic with a virtual buffer to achieve this in LSP-org.
oantolin · 2022-02-05 19:56
Here's the code reformatted in case anyone was curious and found it hard to read all on one line: (cl-loop for c from ?! to ?~ do (let* ((s (format "%d" c)) (spaced (replace-regexp-in-string "\\([0-9]\\)" "\\1 " s))) (cl-loop for b in '(("5" . "C-") ("7" . "C-M-")) do (define-key input-decode-map (kbd (concat "M-[ " spaced "; " (car b) " u")) (kbd (concat (cdr b) (char-to-string c)))))))
Jack-o-tall-tales · 2022-02-05 20:22
Exactly what I needed, thank you!
JovialRoger · 2022-02-05 21:13
I've got a newer laptop I'm installing Ubuntu on and the network adapter isn't working. I found through miloserdov.org that my adapter requires kernel 5.12 or higher. Is there a preferred kernel version that will work best with Ubuntu and Emacs or should I just grab the latest?
rn3aoh · 2022-02-06 11:58
Here’s now I edit comments on reddit now: (use-package edit-server :if (executable-find "pandoc") :init (setq edit-server-new-frame t edit-server-verbose t edit-server-default-major-mode 'text-mode edit-server-url-major-mode-alist '(("github\\.com" . gfm-mode) ("\\(old\\|pay\\)\\.reddit\\.com" . markdown-mode))) (defcustom edit-server-process-alist '(("\\(old\\|pay\\)\\.reddit\\.com/" . (nil markdown-buffer-to-reddit))) "An alist of functions to call to massage edit-server input and output.") :bind ( :map edit-server-edit-mode-map ("C-c C-c" . nil) ;; Avoid clobbering C-c C-c ("C-x C-s" . edit-server-done)) :hook ((after-init . edit-server-start) (edit-server-done . edit-server-process-on-save) (edit-server-start . edit-server-process-on-start)) :config (defun edit-server-get-process-handler () "Doing the DRY thing here." (assoc edit-server-url edit-server-process-alist 'string-match-p)) (defun edit-server-process-on-save () "Process the edit-server buffer on save." (let ((handler (caddr (edit-server-get-process-handler)))) (when handler (funcall handler)))) (defun edit-server-process-on-start () "Process the edit-server buffer on start." (let ((handler (cadr (edit-server-get-process-handler)))) (when handler (funcall handler)))) (defun run-pandoc-on-markdown-buffer (from-format to-format) "Run pandoc on buffer, giving it FROM-FORMAT and TO-FORMAT as arguments." (when (eq major-mode 'markdown-mode) (shell-command-on-region (point-min) (point-max) (concat (executable-find "pandoc") " -f " from-format " -t " to-format) t t))) (defun markdown-buffer-to-reddit () "Process markdown to fit Reddit markdown dialect." (run-pandoc-on-markdown-buffer "markdown-raw_html+autolink_bare_uris+emoji+smart" (concat "markdown-smart+subscript+superscript+strikeout" "-backtick_code_blocks" "-fenced_code_attributes-fenced_code_blocks")))) Requires pandoc and a [Chrome/Firefox extension](https://github.com/stsquad/emacs_chrome), and can obviously be extended. Now I don’t care that Reddit doesn’t like my fenced code blocks. 😄 **P.S.** Not a lisper, I don’t even play one on TV.
zhyang11 · 2022-02-07 00:48
I use iTerm2, which have a "CSI u" mode. I did not use that directly though - IIRC the command line / bash had problems with this mode and I just did not had the will to fix that. iTerm2 support custom key coding definitions, so I just copied some of the key code definitions for the ones I use (like C-.). That has been working alright for me so far.
resixzem · 2022-02-07 19:55
Is it possible to enable sticky modifier keys only on GNU Emacs on linux? The idea sounds wonderful, just type Ctrl instead of holding it. At least that's my impression of what it does, [the "Sticky Modifiers" page on Emacs Wiki is borderline nonsense](https://www.emacswiki.org/emacs/StickyModifiers). The page hasn't been updated for a while. It seems the normal way to achieve this is to enable it everywhere at os-level. I wonder if there is an option I can enable in GNU Emacs. edit: I've enabled it through xfce's accessibility's setting. Instead of the xmodmap way. Honestly, seems to work well. Like holding ctrl still produces the desired effect. Locking mechanism in xfce's setting is weird, so I disable it. Perhaps it's necessary for more complicated sequence. Basically I want to say, I don't notice any changes unless I specifically use sticky keys on emacs or elsewhere.
data_dan_ · 2022-02-09 00:38
I wrote a couple of emacs things in the last couple of weeks: * [Task Repeaters in Org Mode](https://djliden.github.io/posts/20220116-org-time.html) goes into the `++` and `.+`\-style task repeaters for tasks/scheduled headlines. I had previously only been using `+`\-style repeaters, which didn't always advance the next scheduled date into the future. * [Org mode headlines in org source blocks](https://djliden.github.io/posts/20220208-org-source.html): I was writing about org mode but realized that org headlines in my `#+begin_src org` blocks were exporting as actual headlines, not as source code. This article gives some examples of the issue and how to solve it (in short, in an org source block, prepend the headline with a comma).