Weekly Tips, Tricks, &c. Thread reddit / emacs ---------------------------------------------------------------------- AutoModerator · 2022-11-23 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.](htt ps://www.reddit.com/r/emacs/search?q=Weekly+tips&restrict_sr=on&sort=n ew&t=all) Don't feel constrained in regards to what you post, just keep your post vaguely, generally on the topic of emacs. ---------------------------------------------------------------------- tdrusk · 2022-11-23 19:19 I am trying to write a function to replace "C:\Users\Bob\Dropbox" with "Dropbox\". I thought this would work, but it doesn't. (replaces 0 occurrences in a file that has C:\Users\Bob\Dropbox\file.txt in it) (defun sharepoint () (interactive) (replace-string "C:\\Users\\Bob\\Dropbox\\ "Dropbox\\") ) I've tried single \ which reads an an escape character and \\\\ which doesn't find anything. Any tips? ---------------------------------------------------------------------- thetemp_ · 2022-11-23 19:47 >I thought this would work, but it doesn't. (replaces 0 occurrences in a file that has C:\\Users\\Bob\\Dropbox\\file.txt in it) > >(defun sharepoint () (interactive) (replace-string "C:\\Users\\Bob\\Dropbox\\ "Dropbox") ) You're missing the closing double-quote for your first argument. Also, note this advisory from the docstring for the `replace-string` function. This function is usually the wrong thing to use in a Lisp program. What you probably want is a loop like this: (while (search-forward FROM-STRING nil t) (replace-match TO-STRING nil t)) which will run faster and will not set the mark or print anything. (You may need a more complex loop if FROM-STRING can match the null string and TO-STRING is also null.) ---------------------------------------------------------------------- [deleted] · 2022-11-23 19:49 [deleted] ---------------------------------------------------------------------- ares623 · 2022-11-25 02:34 I maintain a small package for a language major mode, providing simple syntax highlighting. How do I make my package work automatically with the various autocomplete libraries out there? Is that supposed to be the responsibility of the major mode? Or a the end user via config? ---------------------------------------------------------------------- konrad1977 · 2022-11-25 06:30 I found this one-liner yesterday, added it it to the `:config` section of **Evil**. `(define-key evil-visual-state-map (kbd "u") 'undo)` Now I can undo in selected region. Like magic. ---------------------------------------------------------------------- Tohiko · 2022-11-25 13:51 Is there a way to write the following statements ``` (define-advice fun1 (:after (&rest _) advice) (run-hook-with-args 'my/hook 'first)) (define-advice fun2 (:after (&rest _) advice) (run-hook-with-args 'my/hook 'second)) (define-advice fun3 (:after (&rest _) advice) (run-hook-with-args 'my/hook 'third)) ``` as a loop operating on a list like this: ``` '((fun1 . first) (fun2 . second) (fun3 . third)) ``` I don't want to use lambda functions because if I executed the file twice (one compiled and one not) two identical advices (one compiled and one not) are added instead of just one. ---------------------------------------------------------------------- helm05 · 2022-11-26 15:38 You need a function that provide completion for your major-mode and add it to \`completion-at-point-functions\` to make \`completion-at- point\` working. You will find several examples in Emacs source code on how to write such a function. ---------------------------------------------------------------------- ares623 · 2022-11-27 07:05 Perfect, thank you! ---------------------------------------------------------------------- oantolin · 2022-11-27 15:46 You could write a macro as follows: (defmacro run-my/hook-w/arg (&rest fn-arg-pairs) (cons 'progn (cl-loop for (fun . arg) in fn-arg-pairs collect `(define-advice ,fun (:after (&rest _) advice) (run-hook-with-args 'my/hook ',arg))))) And call it like this: (run-my/hook-w/arg (fun1 . first) (fun2 . second) (fun3 . third)) ---------------------------------------------------------------------- Tohiko · 2022-11-28 09:34 Thanks, really smart! I guess I can also construct the expression and then pass it to `eval` instead of writing a macro, right? ``` (let ((fn-arg-pairs '((fun1 . first) (fun2 . second) (fun3 . third)))) (eval (cons 'progn (cl-loop for (fun . arg) in fn-arg-pairs collect `(define-advice ,fun (:after (&rest _) advice) (run-hook-with-args 'my/hook ',arg)))))) ``` or is there a reason I should avoid using `eval`? ---------------------------------------------------------------------- CowboyBoats · 2022-11-28 15:51 I'm an immigrant from vim-land using Doom emacs and liking it a lot. I have multiple computers that I do coding on though, and I'm interested in keeping my emacs config (packages I use, preferences, etc) in a file in my `~/Dropbox/config` instead of in `~/.emacs.d` or `~/.doom.d`. Can someone tell me what line of code I should add, and where, to `~/.emacs.d` or `~/.doom.d` to import this new file? ---------------------------------------------------------------------- oantolin · 2022-11-30 01:24 Maybe you should take a hint from the fact that it feels like magic to use built-in commands instead of evil facilities. ;) ---------------------------------------------------------------------- konrad1977 · 2022-11-30 05:38 Yeah, true. I had to remap this one too, forgot that I use *downcase* alot. ---------------------------------------------------------------------- Rotatop · 2022-11-30 06:32 I think you have to set DOOMDIR More at https://github.com/doomemacs/doomemacs/blob/master/docs/gettin g_started.org#configure