reddit / emacs
Weekly Tips, Tricks, &c. Thread
AutoModerator · 2022-03-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.](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.
[deleted] · 2022-03-23 18:40
[deleted]
onearmedphil · 2022-03-24 14:42
I am trying to enter inactive timestamps with a function. So far I have:
(defun insert-now-timestamp()
"Insert org mode timestamp at point with current date and time."
(interactive)
(org-insert-time-stamp (current-time) t))
But this inserts an active timestamp which adds to my agenda.
I can see from this documentation (http://doc.endlessparentheses.com/Fun/org-insert-time-stamp.html) that I should be able to get INACTIVE like so:
(org-insert-time-stamp TIME &optional WITH-HM INACTIVE PRE POST EXTRA)
but I can't figure out how to add the optional stuff. I have tried
(org-insert-time-stamp (current-time) t &optional INACTIVE)
(org-insert-time-stamp (current-time) t &INACTIVE)
(org-insert-time-stamp (current-time) t INACTIVE)
Where do I put the &optional stuff?
29nullvier · 2022-03-24 14:44
**Package Tip**
I am currently trying to "optimize" my Emacs for writing (e.g., org-mode and LaTeX with AucTeX). Since I prefer text (in contrast to source-code) to be in variable-pitch, but stuff like (org-)tables still in fixed-pitch, I was looking for an easy way to combine fixed-pitch and variable-pitch faces.
Doing so I discovered [mixed-pitch-mode](https://gitlab.com/jabranham/mixed-pitch) which does exactly that. :-)
Hastrack · 2022-03-24 17:38
You put `&optional` nowhere, the `&optional` just means that the arguments after itself are not mandatory.
onearmedphil · 2022-03-24 17:53
Thank you, so where do I put INACTIVE?
Hastrack · 2022-03-24 18:44
Nowhere too, INACTIVE is a argument, you have to the specify a correspondent argument, like you did with `(current-time)` that corresponds to `TIME`, so wich argument you want `INACTIVE` to have? You just put it in its place
yousufinternet · 2022-03-24 18:44
Hi, I am starting to learn using `mu` and `mu4e`, I love the interface, but I have an exchange account and I am using `davmail` to be able to sync with it, unfortunately from time to time I need to manually sync (using `mbsync`) and update index `mu index`, that is bearable, but ontop of that sometime running `mu index` will keep indexing the same emails without updating the database, I have to delete the xapian database and rerun `mu init` and `mu index` to make mu detect new emails only, what can be causing this?
sorry if I haven't made my self clear, English is not my native language.
redblobgames · 2022-03-24 18:56
I happened to noticed that I had *rmail* loaded in my emacs. But I don't use rmail. What's up with that? So I found [this r/emacs post](https://old.reddit.com/r/emacs/comments/gngus0/how_find_out_what_code_is_loading_a_package/) that pointed me at ways to track it down.
It turns out org-mode loads all the modules listed in `org-modules`. And org-modules included `ol-rmail`, `ol-gnus`, and a bunch of others. And ol-rmail has `(require 'rmail)`, ol-gnus has `(require 'gnus)`, etc. So that means just by loading an *.org file, it's loading rmail, gnus, eww, erc, and a bunch of other things I am not actually using.
The fix in my case was to get rid of them all:
(use-package org
:init (setq org-modules '())
...
It seems to have partially helped but not fully, so I'm still trying to track down who's using rmail. (maybe the package system??)
redblobgames · 2022-03-24 18:56
Nice! I ended up doing something like that manually, but would've used mixed-pitch-mode if I had known about it.
oantolin · 2022-03-24 20:22
My favorites themes, the modus themes, have an option to do this built in: `(setq modus-themes-mixed-fonts t)`. So with modus you don't really need `mixed-pitch-mode`.
Yet another option is the `org-variable-pitch` package, which I think makes even more things fixed pitch, like the whitespace at the beginning of lines, and the dashes and `[X]` checkboxes for list items.
onearmedphil · 2022-03-24 23:14
I want org-insert-time-stamp to have INACTIVE option.
d_metal_ · 2022-03-25 02:13
(org-time-stamp-inactive)
d_metal_ · 2022-03-25 03:05
long answer using `org-insert-time-stamp`
`(org-insert-time-stamp TIME &optional WITH-HM INACTIVE PRE POST EXTRA)`
`TIME &optional WITH-HM INACTIVE PRE POST EXTRA` These are the function arguments, and are the variables names used by the function.
Docs for the function:
WITH-HM means use the stamp format that includes the time of the day.
INACTIVE means use square brackets instead of angular ones, so that the stamp will not contribute to the agenda.
PRE and POST are optional strings to be inserted before and after the stamp.
Reading the code, the first 2 variables are used as flags (like booleans), with any value means that flag is active, `nil` to indicate to not use the flag.
Try evaluating the following:
(org-insert-time-stamp (current-time)) ; TIME variable is passed with (current-time)
= <2022-03-24 Thu>
(org-insert-time-stamp (current-time) t) ; now let's activate WITH-HM
= <2022-03-24 Thu 19:55>
(org-insert-time-stamp (current-time) nil) ; WITH-HM inactive
= <2022-03-24 Thu>
(org-insert-time-stamp nil nil t) ;; TIME nil, WITH-HM nil, INACTIVE t
= [2022-03-24 Thu]
Usually to activate these flags you pass the letter `t`, you can pass anything that is not `nil`, example:
(org-insert-time-stamp nil nil 91)
(org-insert-time-stamp nil nil 'onearmedphil)
so, why I used `nil` for the value of the variable `TIME` in above example?
If you read the source code of `org-insert-time-stamp` you'll find that it'll call `format-time-string.`
(insert-before-markers (setq stamp (format-time-string fmt time)))
format-time-string has this docs:
(format-time-string FORMAT-STRING &optional TIME ZONE)
A time value that is omitted or nil stands for the current time,
Hope it helps
jumpUpHigh · 2022-03-25 08:33
> `org-variable-pitch`
Is this bundled with orgmode? Where can I find it?
Phil-Hudson · 2022-03-25 10:09
You can use the Customize interface via `M-x customize-option RET org-modules RET` to pick and choose which modules you want enabled.
oantolin · 2022-03-25 10:10
It's on MELPA, so if you have MELPA configured as a package repository, you can simply `M-x package-install RET org-variable-pitch`. The homepage is supposed to be at https://dev.gkayaalp.com/elisp/index.html#ovp but that link didn't actually work for me...
organic-bookworm · 2022-03-25 10:19
**TIP:** Modify [`doom-modeline`](https://github.com/seagle0128/doom-modeline/tree/master/doom-modeline.el) modelines
The `doom-modeline` predefines a bunch of modelines.
While one could define new segments and modelines (see [FAQ #5](https://github.com/seagle0128/doom-modeline#faq)), there's no *easy* way of reusing or modifying existing ones.
Here's an simple hack to record modeline definitions:
(defvar my/doom-modeline-alist nil
"Alist ((name lhs rhs) ...) of `doom-modeline-def-modeline' function arguments.")
(advice-add #'doom-modeline-def-modeline :around
(defun my/doom-modeline-def-modeline-a (fn name lhs &optional rhs)
"Advice `doom-modeline-def-modeline' to store arguments in the `my/doom-modeline-alist' variable."
(prog1
(funcall fn name lhs rhs)
(setf (alist-get name my/doom-modeline-alist) (list lhs rhs)))
))
Eval this snippet **before** loading `doom-modeline`.
E.g. in Doom Emacs with `:ui modeline` module enabled I would do
(use-package! doom-modeline
:defer t ;; Rely on Doom's configs
:init
;; <snippet>
)
It's up to you whether to abstract `my/doom-modeline-alist` or use it directly.
Now I can
(cl-loop for (name lhs rhs) in pp/doom-modeline-alist
do
;; Change `lhs' and `rhs'...
;; Update modeline.
(doom-modeline-def-modeline name lhs rhs)
)
**EDIT:**
* use `cl-loop` with destructuring binding instead of `mapc` in the last snippet
T_Verron · 2022-03-25 11:53
Specifically for org tables, there is also [valign](https://github.com/casouri/valign) to make them look nice and aligned, even with a proportional font.
T_Verron · 2022-03-25 11:57
Might be a stupid question, but how do you know that rmail is loaded?
T_Verron · 2022-03-25 11:59
`(org-insert-time-stamp (current-time) t t)`
oantolin · 2022-03-25 16:10
My guess would be `(featurep 'rmail)` returning `t`. It does in my Emacs, I had no idea something was loading `rmail`!
onearmedphil · 2022-03-25 17:21
> (org-insert-time-stamp (current-time) t t)
I get invalid function when I do that.
onearmedphil · 2022-03-25 17:21
this doesn't include the time.
onearmedphil · 2022-03-25 17:25
Thanks for explaining. That kind of helped.
This is what I needed and was able to figure out with some analysis of your post, so thanks.
(org-insert-time-stamp (current-time) t t)
d_metal_ · 2022-03-25 17:57
Lol sorry
jumpUpHigh · 2022-03-25 18:14
I found it on github from Melpa: https://github.com/cadadr/elisp#org-variable-pitchel
Thanks for pointing it out on melpa.
onearmedphil · 2022-03-25 21:04
How can I evaluate a buffer and print the output to Messages or somewhere?
redblobgames · 2022-03-26 00:58
Thanks!
redblobgames · 2022-03-26 00:59
In addition to `(featurep 'rmail)` you can look at the `features` variable.
In addition to org-mode loading rmail, I think list-packages or something package-related is loading rmail on my system.
redblobgames · 2022-03-26 01:00
Hm. `(org-insert-time-stamp (current-time) t t)` is working for me. It inserts a timestamp `[2022-03-25 Fri 17:59]`
onearmedphil · 2022-03-26 01:16
Yeah you got it. I must have mistyped it, sorry.
holgerschurig · 2022-03-26 07:47
This is my current incarnation of moving from error to error:
(defun my-next-error (&optional arg)
(interactive)
(let ((p))
(when (and (boundp 'flymake-mode) flymake-mode)
(ignore-errors
(save-excursion (call-interactively #'flymake-goto-next-error arg)
(cl-pushnew (point) p))))
(when (and (boundp 'spell-fu-mode) spell-fu-mode)
(ignore-errors
(save-excursion (call-interactively #'spell-fu-goto-next-error)
(cl-pushnew (point) p))))
(ignore-errors
(save-excursion (call-interactively #'next-error arg)
(cl-pushnew (point) p)))
(unless (null p)
(goto-char (apply 'min p)))))
(defun my-previous-error (&optional arg)
(interactive)
(let ((p))
(when (and (boundp 'flymake-mode) flymake-mode)
(ignore-errors
(save-excursion (call-interactively #'flymake-goto-prev-error arg)
(cl-pushnew (point) p))))
(when (and (boundp 'spell-fu-mode) spell-fu-mode)
(ignore-errors
(save-excursion (call-interactively #'spell-fu-goto-previous-error)
(cl-pushnew (point) p))))
(ignore-errors
(save-excursion (call-interactively #'previous-error arg)
(cl-pushnew (point) p)))
(unless (null p)
(goto-char (apply 'min p)))))
This code again made sure that I think "at it's core, Lisp sucks". `p` is supposed to be a local variable list of found error positions. At least this is what I thought `let` defines. And at first I used `add-to-list` to add elements to it.But it turned out that with `-*- lexical-binding: t; -*-` at the top, I always got errors that `p` is undefined. `add-to-list` thinks that `p` is global, what the heck?
However, `cl-pushnew` worked. It does more, e.g. check if the to-be-added item is already in the list, which I don't really need for my code. But at least it works with the local `p`.
Really, it's actually bad that we have two different functions to add things to a list. And that they have surprising subtle differences is bad, too. For me, Lisp sucks, and I only use it because I have to. It's nothing that I enjoy.
arosa09 · 2022-03-26 14:07
Also look at TeX-fold-mode and xenops. The only this I am trying in Auctex is dragndrop images and files.
oantolin · 2022-03-27 02:43
`add-to-list` also checks if the item is already present in the list. The function you probably wanted is `push`. Also, you should have gotten the following error message when you attempted to use `add-to-list`:
`add-to-list' can't use lexical var `p'; use `push' or `cl-pushnew'
oantolin · 2022-03-27 02:57
In version 9.5.2 `ol-rmail` does *not* have `(require 'rmail)`, so `ol-rmail` was *not* the culprit in my case. It turned out that `ol-gnus` does `(require 'gnus-util)`, and `gnus-util` in turn does `(require 'rmail)`. Since I definitely need `ol-gnus` I gave up on not loading `rmail`. :)
By the way, of the methods of tracking down how a library got loaded in your link, I think the easiest is looking at `load-history` it tells you *everything*! It's probably best to give it its own buffer by doing `M-x pp-eval-expression RET load-history`.
redblobgames · 2022-03-27 03:59
Yeah, `load-history` is great! I'm tempted to feed the provide/require entries into a graphviz visualization.
holgerschurig · 2022-03-27 06:06
No, I didn't get this error message (Emacs 28.0.92).
franciumfluoride · 2022-03-28 01:41
New to emacs, coming from vim. I'm looking for some advice on packages to recreate the vim environment I've configured over a number of years.
The one thing I haven't found yet is a floating file search and a floating fuzzy search package. I'd really prefer a floating one as opposed to one that pops up at the bottom. With neovim, it's possible to do this easily now. With emacs, I've come across a few packages for floating windows, but I'm not sure if there's anything better.
Screenshots for reference, my vim environment with the floating file and text search
- Full text fuzzy search https://ibb.co/Hnb1ShS
- File fuzzy search https://ibb.co/FWs8Q9q
MistakeNotDotDotDot · 2022-03-28 03:22
Something like vertico-posframe (combined with vertico) would do what you want, I think. consult will get you all the fancy interfaces for things like "fuzzy search all files in the given project" if you use consult-ripgrep and consult-find.
sudhirkhanger · 2022-03-28 07:07
Is it possible to install `enchant` binaries using emacs itself? I want to keep my emacs config self-sufficient and avoid installing packages from outside.
by_wicker · 2022-03-28 15:08
and I think `vertico-multiform` will let you select different display for different completions - e.g. popup for files but not for search.
... though it's something on my list to configure, haven't used it myself yet.
redblobgames · 2022-03-28 22:04
Ok, I did this!
(defun -my/load-history-one-to-graphviz (module)
"(internal) Convert one entry of load-history into a graphviz string"
(cl-loop for entry in (cdr module)
if (and (consp entry) (eq (car entry) 'provide))
collect (cdr entry) into provide
if (and (consp entry) (eq (car entry) 'require))
collect (cdr entry) into require
finally
return
(and provide
(cl-loop for dependency in require
concat (format " \"%s\" -> \"%s\";\n" (car provide) dependency)))
))
(defun my/load-history-to-graphviz ()
"Convert load-history provides/requires into a graphviz graph"
(interactive)
(with-current-buffer "*scratch*"
(insert "digraph G {\n rankdir=\"LR\";\n")
(insert (cl-loop for module in load-history
for graphviz = (-my/load-history-one-to-graphviz module)
concat (or graphviz "")))
(insert "}\n")))
This will insert a graphviz file into my *scratch* buffer, and then I paste that into https://dreampuf.github.io/GraphvizOnline/ to get a visualization. I've already discovered some unexpected dependencies…
jokem59 · 2022-03-29 05:08
When using `scp:<username>@` then pressing `Tab` to auto populate results, I see a lot of entries I no longer use. Where is emacs pulling this historical list from and how can I edit it?
rguy84 · 2022-03-29 14:07
I have
(defun me/org-inactive-timestamp-insert()
(interactive)
(org-insert-time-stamp nil t t nil nil nil)
)
Sudo_Brew · 2022-03-29 14:36
Like, `(eval-buffer)`?
onearmedphil · 2022-03-29 17:44
That’s what I tried but it doesn’t show the output of my print statements. Should it?
Sudo_Brew · 2022-03-29 18:08
It does work for me, and I can print things to Messages. If you just do a super simple `(message "hi")`, does that work for you?
onearmedphil · 2022-03-29 20:04
Thank you, that was helpful. Didn't know about using (message "xyz").
This is what I am trying to do as an experiment:
(setq cat '(meow meow meow))
(setq dog '(woof arf woof))
(message cat)
(message dog)
And I am getting eval-buffer: Wrong type argument: stringp, (meow meow meow)
I'm basically trying to learn how to make simple programs with lisp. Any tips?
EDIT: I figured it out. This link was helpful https://wilkesley.org/~ian/xah/emacs/elisp_basics.html Thanks for your help.
Sudo_Brew · 2022-03-30 15:58
Excellent, glad you found a helpful resource!