reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-07-06 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.
isamert · 2022-07-06 08:22
I sometimes clone stuff with https instead of ssh, so this fixes that: (defun isamert/git-origin-switch-to-ssh () (interactive) (when-let* ((https-origin (s-trim (shell-command-to-string "git config --get remote.origin.url"))) (it (s-match "https://\\(.*\\)\\.\\(com\\|net\\|org\\)/\\(.*\\)" https-origin)) (ssh-origin (format "git@%s.%s:%s" (nth 1 it) (nth 2 it) (nth 3 it)))) (shell-command-to-string (format "git remote set-url origin %s" ssh-origin)))) It works for github/gitlab etc. You need to extend the regexp for making it work for more obscure addresses.
remillard · 2022-07-07 13:00
I've got a strange situation with magit that I get closer to resolving but can't quite crack the solution on it. Here are the situation and symptoms. I am in a Windows environment (this is a work machine, the OS environment is not malleable.) 1. I have two projects that are git repositories local and with origin remotes. 2. I have three methods of dealing with git: CLI git, emacs magit git (which should just be CLI but I'll get to that in a moment), GitKraken. 3. Project A: I am able to status, stage, commit, and push with all three tools with equal results. I have tested each of these. 4. Project B: I am able to status, stage, commit, and push with CLI git, and GitKraken. I am only able to status, stage, and push with emacs magit! If I try to commit with magit, it'll give me the error that I'm not in the repository. I do not know why the other commands work fine. I mention both projects because it's clearly not an issue with the installation or authentication of any of these tools. It is something very specific to one project. Unfortunately Google searching has been worthless for this problem. The failure mode of "Error not in repository" seems to be Git's fallback error that can mean a lot of different things and I've not found any situation where someone had such a specific situation. I figure since CLI git can be used for the project that is not working with magit, it has something to do with the location that emacs magit is using to execute the command. I have my git repositories setup and I can see everything with `magit-list-repositories` but perhaps for some reason it is not running commit from within the directory? I really don't know. It's not a showstopper because I have workable solutions, but it's a problem that just nags at me because I feel like there's something that needs setting up that will just fix everything but nothing seems relevant to this error message. Thanks!
Qwarctick · 2022-07-07 14:57
Is it possible to jump back when reading documentation with `helpful.el`. I mean, I search for a function with `C-h f`, then I follow a link for an other help, and I want to go back.Is it possible ?
MmmCurry · 2022-07-07 15:36
If you're in help-mode, `help-go-back` should navigate to where you were before following a link. It should be bound to `l` by default. Do `C-h m` (`describe-mode`) while in help-mode to see a list of this and other bindings.
Qwarctick · 2022-07-07 15:43
Oh many thanks ! I will test it
tiktaaliki · 2022-07-07 17:10
a question about something minor that's really bugging me: i changed themes recently, and this new theme does not have a color for plain list numbered/ordered items, unlike the previous theme. other than this small quirk I have been quite happy with my new theme. I have been unable to determine what the face name is to change it so that the ordered list numbers are in a different color. Putting the cursor over it and choosing "customize-face" or "describe-face" doesn't recognize this as being different from just the regular default face. I have tried a couple search terms on a search engine but i am not finding what I need. 1. example 2. list 3. here in this example, I want to customize the 1. 2. and 3. so they are visually distinct from the content of the list. Any guidance toward this would be much appreciated, thank you!
yigitemres · 2022-07-07 23:36
Simply put cursor and call `describe-char`to which face color you liked. Near bottom you see `There are text properties here:` prompt and you see the name of your face. There are text properties here: face font-lock-constant-face fontified nil After determine what face you liked to put your "list of items", you have to: (font-lock-add-keywords 'mode-name '(("regexp with grouping" which-group-#-to-change 'your-liked-face-name))) For example I create functions named `pkg-require` and `pkg-install` and I want that arguments of this functions have a `constant-face`. I do the following: (font-lock-add-keywords 'emacs-lisp-mode '(("(\\(pkg-require\\|pkg-install\\)\\_>[ '\\|\\s(]*\\(\\(?:\\(\\sw\\|\\s_\\|\\\\.\\|\\)\\)+\\)?" 2 'font-lock-constant-face)))
Qwarctick · 2022-07-08 08:21
Wow Nice, I tested and it's exactly what I am looking for.
tiktaaliki · 2022-07-08 12:25
ah thanks for your reply. your reply led me to reload the old theme and use "describe char" on a plain list. it turns out the variable i need to modify is org-list-dt. i had thought this wasn't it because I thought this was specifically for when you have 1. item :: definition, but i realize now that both are formatted the same. thank you!!
[deleted] · 2022-07-09 02:45
[deleted]
_viz_ · 2022-07-09 15:34
A couple default mouse pointer settings that annoyed me: 1. Pointer becoming invisible as soon as you start typing. Set make-pointer-invisible to nil. 2. If you don't like the ibeam cursor shape when the pointer is over text, then change x-pointer-shape (also see x-win.el and (info "(elisp) Pointer Shape")). I have it set to the value of x-pointer-left-ptr.
[deleted] · 2022-07-11 05:43
[deleted]
Stefan-Kangas · 2022-07-12 01:06
Make clicking on files in Dired buffers open in the current window: (define-key dired-mode-map [mouse-2] #'dired-mouse-find-file) (This works thanks to `mouse-1-click-follows-link`.)
takutekato · 2022-07-12 06:05
About `helpful` but not `help`, there's feature request from 2020:[https://github.com/Wilfred/helpful/issues/250](https://github.com/Wilfred/helpful/issues/250) But if you only want a simple way to go back: ```elisp (define-key (kbd "<") (lambda () (interactive) (funcall helpful-switch-buffer-function helpful--start-buffer)) ```
trae · 2022-07-12 18:28
Does magit use git cli internally? Maybe alias git to a shell script and dump env what’s getting executed?
remillard · 2022-07-12 19:08
It does. Additional tinkering with this over the past week suggests it's just something to do with Windows and I cannot adequately configure it without side effects. Git wants to run emacsclient which requires a daemon. If I have it run a new instance of Emacs, it's long to start up, and doesn't seem to recognize the commit where it's saved. If I try to setup a daemon, then Emacs clients for regular use -- well there's some weird stuff happening in how frames are created and how it reads information from init.el (e.g. a lot of packages are NOT enabled, despite them being marked ensure, though color theme works, but fonts do not). Anyway, long story short, I've more or less given up on magit in a Windows environment. I have a good working setup minus that and using either git CLI or GitKraken depending on the situation so it's not necessary. Bugs me that I can't figure it out though, but no time to make this a working solution because work has to get done also.
trae · 2022-07-12 20:14
Fair, I missed the "windows" part. Maybe this will be helpful: https://emacs.stackexchange.com/a/10095/22240 Basically drop into a debugger when a certain error message is displayed. Do you know how to use edebug?
remillard · 2022-07-12 20:33
Not extensively, though of the two problems: 1) When my init.el works fine, and non-daemon mode, when magit failed, it would say that Git said it was not in a repository directory, and would also announce an error trying to execute emacsclient (hence trying to go down the daemon route.) 2) When in the daemon mode, there was never any error per se, just it would not run all of init.el and I couldn't figure out why it skipped some things (pretty much anything invoked with `use-package` and also keyboard mappings) and paid attention to others (sometimes window frame position was obeyed, and color theme was obeyed, but font was not). So I'm not entirely sure debugging would help if there's no actual error. The magit error will show with `$` after it fails and it'll give the command it tried to execute, and the error git reported. In any event, I got royally stuck and ran out of time to really debug it. I truly appreciate the suggestions though, I got zero other responses to this or the other issue with Windows daemon mode.
trae · 2022-07-13 01:35
That's really odd and frustrating.. Your init is running fine for GUI mode but not demon mode? That doesn't sound right for sure. The only thing I can think of is --debug-init...'cause maybe the gui mode isn't running successfully either? Good luck!
jeffphil · 2022-07-13 05:54
Have you looked at this page around "Simple server setup"? https://www.emacswiki.org/emacs/EmacsMsWindowsIntegration
Sound4Sound · 2022-07-13 07:40
Emacs is the most frustrating and rewarding experience I've had in a while. Have been learning org mode from zero for 2 weeks now, specially the literate coding and publishing features. I've been about to quit a couple of times but wow its worth it once you get to the other side. I know this thread is about to be over, I just wanted to share somewhere, my tip then is to not give up. Its worth it.
remillard · 2022-07-13 12:55
Yes. I've done it with the simple MS-DOS batch file, and the more elaborate (with logging) PowerShell. The problem isn't that the daemon doesn't come up. It does! And emacsclientw will launch a frame. The issue is that the frame does not seem to have many things enabled, certain keybinds, certain packages, font -- but it does have some things that were in init.el like color scheme. There aren't any errors to debug that I can tell, nothing shows up in *Messages*. It's just ignoring some things. The daemon is up and runs fine though.
remillard · 2022-07-13 12:59
Thanks! And yeah, that's what happens when I'm in that path. The daemon starts fine -- could try debug init there perhaps but I would probably have to do some jiggering to get debug output to show up since the daemon doesn't have anything I can easily inspect -- hopefully would go to the terminal perhaps. And then emacsclientw works fine, but doesn't run everything. However ye olde basic `runemacs.exe` without the daemon will load the entire init.el just perfectly and show up exactly in the right spot on the screen. I appreciate the thoughts. Maybe I'll take up the lance on it again when I have time, but actual code has to be slung here and not faffing about with the editor.
jeffphil · 2022-07-13 13:16
I'm not a windows user, but probably HOME related. This is logic for loading init.el on windows, hope it helps: https://www.gnu.org/software/emacs/manual/html_node/efaq-w32/Location-of-init-file.html
remillard · 2022-07-13 13:27
Well, I have the HOME environment variable set. There IS a weirdness that I haven't pursued because if I have to go this way, just fuck it, I'll forget about it and chalk it up as a Windows incompatibility. Unix home is your user directory. Windows (as of 7 and 10 upwards) does have a user directory too `c:\users\<name>\` HOWEVER they also have some sort of application guideline that application specific settings go in `%APPDATA%` environment location which is usually `c:\users\<name>\AppData`. However coming from a *nix background this is just freaking insane and I don't want to store `.emacs.d` in `%APPDATA%`, I want it under home, to wit `c:\users\<name>\.emacs.d\` where it OUGHT to be. So if that's ultimately the solution, I'll just forget the whole dumb thing. My environment sets HOME correctly, and the PowerShell script also sets the starting directory as HOME and I've done everything I can to put HOME in the correct (to me) home location. It is entirely possible though that there's something hardwired into the Windows binary that forces it to look at `APPDATA` though that I cannot control.