reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-09-14 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.
ispinfx · 2022-09-14 09:32
How to get progress bar (e.g. `cargo install/apt install/tqdm`) displayed nicely in `comint` buffers? Is there a general (the code in the post does not work for `cargo install`) solution like this one: https://oremacs.com/2019/03/24/shell-apt/ ?
zupatol · 2022-09-14 09:38
After years of using emacs, I wrote my second ever elisp function to open on github the code I'm browsing in emacs. (defun open-on-github () (interactive) (let ((repo-url (magit-git-string "remote" "get-url" "--push" "origin")) (commit-hash (magit-git-string "rev-parse" "HEAD")) (start-line (if (use-region-p) (line-number-at-pos (region-beginning)) (line-number-at-pos))) (end-line (if (use-region-p) (line-number-at-pos (region-end))))) (unless repo-url (error "not in a git repo")) (browse-url (concat (substring repo-url 0 -4) "/blob/" commit-hash "/" (substring buffer-file-name (length (projectile-project-root))) "#L" (number-to-string start-line) (if (and (use-region-p) (< 0 (- end-line start-line))) (concat "..L" (number-to-string end-line))) ))))
PriorOutcome · 2022-09-14 10:32
I find it pretty useful (for debugging etc) to override the default projectile mode line indicator and show the projectile project type of the buffer instead, which can be done pretty easily if you're a use-package user with https://elpa.gnu.org/packages/delight.html: ``` (use-package projectile :delight '(:eval (format " P[%s]" (projectile-project-type))) :config (setq foo "bar")) ```
PriorOutcome · 2022-09-14 10:34
Follow up: does anyone know how I can make sure this is always for example the nth indicator shown on the mode line?
howardthegeek · 2022-09-14 14:38
I just learned that in eshell, $$ is replaced with the output from the last command.
trae · 2022-09-14 16:38
Hey folks, Is there a package/piece of code out there to: 1. pop up a frame 2. execute arbitrary code 3. close frame on completion Kind of like [emacs-everywhere](https://github.com/tecosaur/emacs-everywhere/) but for arbitrary code.
trae · 2022-09-14 16:41
Congrats! :) Have you seen https://github.com/sshaw/git-link/ ? It works with multiple forges as well.
donio · 2022-09-14 17:03
The `browse-at-remote` package does this as well.
meain · 2022-09-14 19:05
Why not use `emacsclient -ce "command"`?
zupatol · 2022-09-14 19:16
Haha yes, it was unlikely this didn't exist, but I didn't find it. Thanks for the link!
trae · 2022-09-14 19:25
This is excellent, I wasn't aware of the `-c` flag. Any suggestions on how destroy the frame cleanly, after the `command` executes?
Ghosty141 · 2022-09-14 19:43
vterm is the only shell that *really* worked for me. Handles progress bars etc.
Hammar_Morty · 2022-09-14 20:25
Just call `(delete-frame)` as the last command `(progn (a-function) (delete-frame))`
sarit-hadad-enjoyer · 2022-09-14 21:42
That's neat! What are you using it for?
trae · 2022-09-14 21:49
Thanks this is great!
zupatol · 2022-09-14 21:57
I use links to code on github in documentation and bug reports
ispinfx · 2022-09-15 00:30
vterm is a term, not a shell...
Ghosty141 · 2022-09-15 04:20
Woops yeah.
alecStewart1 · 2022-09-15 15:09
For those of you who use Flymake: how do you enable and start it in modes? I had it hook into `prog-mode` in a `use-package` form: :hook (prog-mode . flymake-mode) But for example in shell script mode, it doesn't start until I `M-x flymake-start`. I also have [`flymake-collection`](https://github.com/mohkale/flymake-collection) installed and, specifically for shell scripts, I have this bit in a `use-package` form: :flymake-hook (sh-mode (flymake-collection-shellcheck :predicate (lambda () (executable-find "shellcheck")))) Any tips?
mmontone · 2022-09-15 15:58
It is possible to add hosted git repositories as package-archives. Like this for example: ```lisp (add-to-list 'package-archives '("emacs-snippets" . "https://codeberg.org/mmontone/emacs-snippets/raw/branch/master/")) ``` Then you can browse the packages in your git repository with `package-list-packages` and friends. This adds EmacsWiki elfiles as repository: ```lisp (add-to-list 'package-archives '("emacswiki" . "https://raw.githubusercontent.com/varlardohaeris/emacs-archives/master/emacswiki/")) ```
thoomfish · 2022-09-15 18:51
I'm fiddling with switching from Doom to my own config so that I can more easily manage it with Nix/home-manager. Immediately ran face-first into a brick wall trying to set up `straight`. The sum totality of my `~/.config/emacs/init.el`: (let ((bootstrap-file (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) (bootstrap-version 6)) (unless (file-exists-p bootstrap-file) (with-current-buffer (url-retrieve-synchronously "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" 'silent 'inhibit-cookies) (goto-char (point-max)) (eval-print-last-sexp))) (load bootstrap-file nil 'nomessage)) fails with the following error: Cloning into '/Users/<username>/.config/emacs/straight/repos/nongnu-elpa'... remote: Counting objects: 392978, done. remote: Compressing objects: 100% (135497/135497), done. error: object 2699d230e3b592ae42506d7b5c969a7ac6a4593c: zeroPaddedFilemode: contains zero-padded file modes fatal: fsck error in packed object fatal: fetch-pack: invalid index-pack output This is on macOS 11.6.8, with Emacs 28.1 and git installed through Nix. The only reference I can find to this issue is [here](https://github.com/radian-software/straight.el/issues/762#issuecomment-1163278778), which suggests the workaround of manually cloning NonGNU ELPA with fsck disabled, but that feels like a hack I'd rather not do when trying to set up a reproducible config, so I'm giving up for now and waiting a few months to see if the issue resolves itself.
karthink · 2022-09-15 22:39
Your best bet is installing `coterm` and turning on `coterm-mode`. It's got issues with some repls and some terminal escape characters, but does a decent job on the whole.
lianacrossk7n · 2022-09-16 00:17
I may be unique in that I often want to kill all whitespace up to a word if the point is on whitespace, otherwise I want to kill the word (rather than kill whitespace and the word.) (defun maybe-backward-kill-word (arg) "Removes all whitespace backward up to the next non-whitespace character. If the first character left of the cursor is not whitespace then remove the word. (I bind this to C-backspace.)" (interactive "p") (if (looking-back "[ \t\r\n]") (let ((start (point))) (re-search-backward "[^ \t\r\n]" nil) (forward-char 1) (delete-region (point) start)) (backward-kill-word arg))) (defun maybe-kill-word (arg) "Removes all whitespace up to the next non-whitespace character. If the first character right of the cursor is not whitespace then remove the word. (I bind this to C-delete and M-d.)" (interactive "p") (if (looking-at "[ \t\r\n]") (let ((start (point))) (re-search-forward "[ \t\r\n]+" nil) (delete-region (point) start)) (kill-word arg)))
ispinfx · 2022-09-16 00:40
Thanks for you suggestion. But it [does not seem](https://s1.328888.xyz/2022/09/16/cemPo.png) to work well with `cargo`...
karthink · 2022-09-16 18:56
That's a shame. Sorry, I don't know of any other solution short of implementing the escape character handling yourself.
PriorOutcome · 2022-09-17 12:22
Update, I've asked here: https://emacs.stackexchange.com/questions/73658/change-the-order-of-minor-modes-on-the-modeline
agumonkey · 2022-09-17 20:12
i love emacs / repo helpers
TiMueller · 2022-09-18 04:59
Is there a way to switch back und forth between two different directories in Dired? I would love to use the mark-ring, e.g., press a key to mark the current directory, go to a different directory, and later press a key again to instantly go back to the marked directory.
MunsterPlop · 2022-09-18 17:18
You can do that in multiple ways. Here's two: 1- Bookmarks: create bookmarks with `C-x r m`, jump to one with `C-x r b`, open bookmark menu with `C-x r l`. 2- Registers: store point in register with `C-x r SPC <key>`, jump to it with `C-x r j <key>`.
takeonrules · 2022-09-19 02:37
Congrats on writing your Lisp function. There's always prior work, but for myself I find writing my own as a great way to learn how to write more.
TiMueller · 2022-09-20 06:40
Thank you very much! I had never before tried out registers, now I did, and it's fun! Also, I found out that I can use org-mark-ring too, it just hadn't worked because I let dired close old buffers when going up a directory. Now that I let the dired buffers open, I can use my keys for `org-mark-ring-push` and `org-mark-ring-goto`.
[deleted] · 2022-09-20 08:23
[deleted]