Skip to main content


elisp question

I just put a call to eval in my code and I feel dirty now.

The context went something like this:

(eval (cons 'concat (my-function arg1 arg2)))

I had initially hoped to use
(concat . (my-function arg1 arg2))

...but this resulted in a call to
(concat my-function arg1 arg2)

Which was not what I expected.

Is there a better way I could've written this?
#emacs #lisp #elisp

Edit: Got my answer. I wanted:

(apply 'concat (my-func arg1 arg2))

Edit 2:
It turns out the code I really wanted was:

(string-join arg2 arg1)

I love reinventing the wheel because I didn't know it was already there.

Edit 3:
Here's the actual code:

(defun lambdamoo-run-text-replacements (str)
  "Perform text replacements on the string"
  (dolist (vals lambdamoo-text-replacements)
    (let* ((from (car vals))
           (to (cdr vals))
           (split (split-string str from)))
      (setq str (string-join split to))))
  str)

Let's see if there's anything else I've reinvented here.
in reply to Jonathan Lamothe

elisp question

Sensitive content

#lisp
in reply to Simon Brooke

elisp question

@Simon Brooke What I was looking to do was to call concat with the list returned by (my-function arg1 arg2) used as arguments.

As it turns out, all the functionality I was looking for was already supplied by the string-join function. I just didn't know it existed.

in reply to Simon Brooke

elisp question
@Simon Brooke Also, I don't like calling eval unnecessarily, as it can open you up to security vulnerabilities if not done carefully.


I just wrote a bunch of #elisp code like this:
(catch :abort
  ;; do something
  (when condition
    (message "A bad thing happened")
    (throw :abort nil))
  ;; do something else
  )

When the functionality I really wanted was:
(progn
  ;; do something
  (when condition
    (user-error "A bad thing happened"))
  ;; do something else
  )

I knew the former felt sketchy, but I couldn't think of a better way to do it until just now.
#emacs #lisp

FOSS Dev reshared this.



#Elisp logic:

All interned symbols can be found in a lookup table. This table is bound to the obarray symbol.

Hang on a minute...

I can only assume that the underlying C code has its own pointer to this table and the obarray symbol is only provided as a convenience for elisp functions that can't see this pointer?
#emacs #lisp

in reply to Jonathan Lamothe

No no, the obarray you see from elisp is the same one used by the reader. Elisp is an old-style Lisp here, and the obarray is a first-class thing: you can make a new one, rebind obarray, etc.

That's the sort of thing people don't do much anymore, but used to do. The documentation covers it reasonably well gnu.org/software/emacs/manual/…



Wrote my first non-trivial #elisp macro yesterday. Macros were the thing that scared me away from #lisp the first time I tried learning it.
#emacs

Shannon Prickett reshared this.

in reply to James Endres Howell

@James Endres Howell
I'm a little self-conscious about it as non-trivial is relative, but...
(defmacro lambdamoo-chatter-interact
    (func-name to msg docstring fmtstr &rest vals)
  "Define a function for interacting with another player"
  (let ((proc (gensym))
        (str (gensym)))
    `(defun ,func-name (,proc ,str)
       ,docstring
       (let ((,to lambdamoo-chatter)
             (,msg (substring-no-properties (lambdamoo-command-text ,str))))
         (if ,to
             (funcall lambdamoo-send-line ,proc
                      (format ,fmtstr . ,vals))
           (message "No chatter specified"))))))
in reply to Jonathan Lamothe

That's awesome. I need to hear my own advice, of course, but don't be inhibited to share something that isn't finished. It's the Fediverse! We're all anarchists! The kind sort, I mean.

Lisp macros are just so powerful.

in reply to James Endres Howell

@James Endres Howell They really are. They're a little bit of a mind bender until you really get them, but once you do they're such a game changer.
in reply to Jonathan Lamothe

Wait, how do you get the awesome code formatting? Anybody know how to configure this on fediscience.org?

AM I GOING TO HAVE TO SPIN UP MY OWN INSTANCE AGAIN

in reply to James Endres Howell

@James Endres Howell Frendica has a markdown add-on.

I just typed:

```lisp
...code...
```

Typing that however was trickier.


I'm finally MOOing from #Emacs. I've still got a bunch of work to do to port my customizations over from my old client, but it's Emacs... I'm sure it can do that.
#LambdaMOO #moo #mud


I am dangerously close to unleashing my first #emacs package on the public. It's nothing fancy and still relatively niche, but I deem it potentially useful enough to be worth publishing.

There are a couple small features I want to add and a few things that still need some polish, but it's almost ready for a version 0.1 release.

It's not anything ground breaking or anything. I'm still pretty much an #elisp novice, but I'm proud of it anyway.

More details when it's released.

in reply to Jonathan Lamothe

We can never have too many elisp packages out there! Almost welcome to the club! ;)
in reply to Álvaro R.

@Álvaro R. At this point all I need to add is a README and two features (which will mostly reuse code I've already written just in a slightly different way).

Surprisingly enough, the hardest part of the whole project was getting it to display numbers with thousands separators. That code might exist in the bowels of the calc package, but it was easier to just roll my own.

in reply to Jonathan Lamothe

your package, your rules! Sometimes rolling your own is more fun and you get exactly the UX you wanted.
in reply to Jonathan Lamothe

Okay, my first #Emacs package is officially released. It was strongly inspired by @Soroban Exam Website's work, providing practice tools for the #soroban. This is the first Emacs package I've ever released. It's probably not perfect, but I welcome feedback on how it can be improved.

I wonder if there is an overlap of more than say five people who are both soroban and emacs users. 🙃

Anyhow, it can be found at: codeberg.org/jlamothe/soroban

reshared this

in reply to Jonathan Lamothe

vim guy here. happy to see I inspire others...

May be you could post on our forum. Not sure you will get more users, though

in reply to Soroban Exam Website

@Soroban Exam Website Might as well. I wrote it mainly for myself, partly because I don't own a printer and this makes it easier to practice when working from a computer screen, but also just to see if I could.

Still, if someone else is going to find it useful, that's probably the place I'll find them.

in reply to Jonathan Lamothe

May be you didn't see you that you can generate an interactive HTML output, on the site.
That was designed for people who don't want to print.

Should I make it more visible?

This entry was edited (1 week ago)
in reply to Soroban Exam Website

@Soroban Exam Website Yeah, that's what I'd been using. I just wanted sonething that worked offline. It's also got some tweaks that make it easier to see what line I'm on when doing additions since I can't slide my soroban over the page.


elisp shenanigans
I just put a call to format inside my call to format. This is probably fine, right?
#emacs #elisp
in reply to Jonathan Lamothe

elisp shenanigans
Side note: is there a way to tell format to use a thousands separator? That'd be nifty, but it doesn't look like there is a way.
in reply to Jonathan Lamothe

elisp shenanigans

Sensitive content

in reply to Alex

elisp shenanigans
@Alex I'll have a look. Worst case scenario is that I have to roll my own.
@Alex


Another #elisp question: Why does #Emacs have separate bits for the meta key (2**27) and alt (2**22)? Aren't they the same key, or is it a remapping thing like the ESC prefix?
in reply to Jonathan Lamothe

Meta and ALT are not the same key.
The original keyboards used long ago had Ctrl, Super, Hyper, Meta, and ALT keys. We now map Meta (i.e. ESC) to the Alt key on our keyboards as a convenience. I do not believe there is a way, on modern keyboards, to have both META and ALT mapped to a key. We can have Super, and Meta. I can't recall if I was able to map Hyper on a modern keyboard.


elisp nonsense

I've been playing around with keymaps. Apparently they can be used to create menus that give the user a visual list of options. The canonical way to make them is aparently with make-sparse-keymap to create the menu and define-key to add options to it, but this causes some confusing behaviour.

Take the following example:

(let ((menu (make-sparse-keymap "My menu")))
  (define-key menu "a"
    '(menu-item "Foo" foo))
  (define-key menu "b"
    '(menu-item "Bar" bar))
  menu)

Yields the following:
(keymap (98 menu-item "Bar" bar) (97 menu-item "Foo" foo) "My menu")

Each new entry is added to the top of the list, so when the menu is displayed, they're listed in reverse order. This is very counter intuitive.

Now, I understand that the nature of lists in lisp make inserting an element at the top of the list less computationally expensive, but when you've already got to walk the whole list anyway to ensure the key binding isn't already present, this no longer feels like an adequate excuse.

Am I missing something?

#emacs #elisp

reshared this

in reply to Jonathan Lamothe

Define key is my least favorite way to make a keymap.

I like defvar-keymap, bind-keys, if you've got a map create already. Like a sparce map.

General is nice too. But then you have to have that installed.

in reply to Jonathan Lamothe

I think you've got it right. Many who write lisp think of adding to the head of the list as normal, even if they still have to walk it for things like uniqueness checks.


I virtually never set custom keybindings in #Emacs preferring instead to rely on M-x function calls because I had such a hard time finding key sequences that weren't used by something else. Since learning that C-c /[A-Za-z]/ is reserved for user-defined keybindings, I've gone mad with power.

reshared this

in reply to Lens

@Lens @Robert Pluim 🇪🇺 On my system C-z suspends Emacs and drops me back to the terminal until I issue the fg command to bring it back. I use this for issuing git commands. I could probably do this from within Emacs, but I haven't bothered to figure it out.
in reply to Jonathan Lamothe

@rpluim magit is a pretty awesome git porcelain I think you'd like. It's shipped with emacs by default
in reply to Jonathan Lamothe

@lens_r Another option is to run a shell within Emacs. I happen to like vterm, but there's term, eat, eshell and more
@Lens
in reply to Lens

@lens_r magit is awesome, but it's not part of standard Emacs. VC is, but that's not as good as magit for git (it's great however when you're forced to use some other version control system like CVS, since VC provides bindings that work whatever the underlying system is)
@Lens


A thing I keep seeing in #elisp documentation:

If such-and-such a condition occurs within function foo, it will signal an error.

Cool, which error exactly? I mean, I can wrap it in a condition-case and put a handler on t, but...

#Emacs

in reply to Zenie

@Zenie That's an option, but my concern is that the reason they might be vague in the docs is because the specific error might change in future versions.

Perhaps I'm just being overly paranoid.

in reply to Jonathan Lamothe

It's lisp. Stuff doesn't change that much.
Usually errors are obvious and for very specific reasons. You can just catch them and print the message so if anything does change you will know.
I don't think it's worth worrying about.


Long-winded post about Emacs and gripe about modern computing

I think I've been able to pin down what it is that I like about #Emacs so much. When I first started using computers, I was using a TRS-80. If you didn't have a cartridge inserted, It'd boot directly into BASIC where you could program the machine directly. That wasn't a bug, it was a feature.

Modern computing seems to do its best to hide all that stuff away. Everything is treated more like a simple (albeit specialized) appliance, not a powerful machine that can be made to do literally anything you want. Instead, it's about what the various software vendors want it to do.

Emacs by contrast not only gives you all the tools you need to modify it in any way you want, but actively encourages you to do so. It feels a lot more like the computing systems of old. Perhaps that's not for everyone. There's a reason computers were so niche back in the early days. Most people just didn't care to learn what was going on under the hood, and that's valid. There's something to be said for a tool that just works effortlessly out of the box. Also, to be clear, you don't strictly speaking need to dig into the internals to use Emacs, but I prefer for my technology to serve me, and I'm willing to put the effort in to make that happen.

That's why it's a good fit for me.

in reply to Jonathan Lamothe

Long-winded post about Emacs and gripe about modern computing

Sensitive content

in reply to Shae Erisson

Long-winded post about Emacs and gripe about modern computing
@Shae Erisson Ooh. Be sure to tag me when that drops.


I have come to the conclusion that #Emacs' documentation on how to build multi-file packages is all lies.

screwlisp reshared this.

in reply to Jonathan Lamothe

You could try package-build-create-recipe
It will need to be filled in, but if your headers are correct, with author, packages-required, version, etc.

Edit the recipe for your git. You'll be in recipe mode.
Saving it puts it in .../elpa/recipes/
Building it with C-c C-c will make a package and install it in your elpa..

That might teach you what you need.

It will automatically pick up .el and .texi files.
Not eld, but if you have some odd file, you can add the pattern to the recipe. I have an eld which is not in the list of automatic files.

See the contributing doc at GitHub Melpa.

in reply to Zenie

You want something like this?

oitofelix.github.io/elpa/

See the link to elpa-deploy halfway down.



A thing that's really nice about #Emacs and #elisp: I don't need an internet connection to read the documentation.

reshared this



Dumb #org-mode question:

Is there a way to tell #emacs to generate an agenda view for the current buffer only? Bonus points if the said buffer is not in org-agenda-files.

Edit: Got it.


Pressing < in the agenda dispatcher should do this

Laurent Gatto reshared this.

in reply to Jonathan Lamothe

Per the help doc for org-agenda

"If the current buffer is in Org mode and visiting a file, you can also
first press ‘<’ once to indicate that the agenda should be temporarily
(until the next use of ‘SPC o a’) restricted to the current file.
Pressing ‘<’ twice means to restrict to the current subtree or region
(if active).
"

In other words, execute org-agenda then press "<" before the command you want to run against the agenda.

This entry was edited (4 months ago)
in reply to a world without cars

Question for you - how did you highlight "org-agenda-files" like that in your post?
in reply to a world without cars

@a world without cars I have a markdown plugin on my Friendica server. I just put it between backticks like this: `org-agenda-files`.

This wouldn't work on Mastodon though.

in reply to Jonathan Lamothe

oh interesting. It rendered properly for me on Mastodon but not when I write it that way.
in reply to Jonathan Lamothe

you could do something like this

```
(defun my/file-agenda ()
(interactive)
(when-let ((org-agenda-files (list (buffer-file-name (current-buffer)))))
(org-agenda)))
```



So, I've been using nov.el for #emacs to read epubs. It does a pretty decent job of it, but I have one point of irritation: I can't for the life of me find a way to tell how far through the book I am. Is there some way to see this?

Quiou reshared this.

in reply to Zenie

@Zenie The feature might actually exist for all I know, so I hesitate to put in a feature request. I was just hoping that it was an already solved problem.
in reply to Jonathan Lamothe

I glanced at the code. But I'm not at my usual computer so I can't look at help, the mode or the code more thoroughly. I only just installed it recently so don't know it well.


Just spent a good half hour pulling my hair out trying to figure out why one of the #elisp functions I had just written was always returning nil when I tested it. Turns out, my test was mistakenly passing its inputs to the wrong (but similarly named) function (pivot-table-get-columns instead of pivot-table-get-body).

#Haskell's type system would've caught this. 🙃

#emacs #lisp

in reply to Jonathan Lamothe

C's type system would also have caught it, and it isn't worth a hill of beans.

By caught it what do we mean? This is not a case of some undetected error escaping your attention due to dynamic typing. You know you got a nil which is unexpected and wrong. It's in a test case which catches it.

The only thing a type system would change is that you would instead waste a half hour not understanding how your obviously correct function call can possibly have the wrong return type.

in reply to Kazinator

@Kazinator I feel that that would have been much more useful information. nil is about the least useful failure state there is.


Fine, I'll build an #emacs pivot table package for #org-mode.

reshared this

Unknown parent

mastodon - Link to source
vintage screwlisp account
humor

Sensitive content

in reply to Jonathan Lamothe

Possibly related: github.com/tbanel/orgaggregate , could always use an easier interface =)
in reply to Sacha Chua

@Sacha Chua This looks like it could solve my problem but I've already started down the rabbit hole.
in reply to Jonathan Lamothe

haha, no worries, I'm sure your adventure will help you learn interesting things!
in reply to Sacha Chua

you might also be interested in mastodon.online/@hajovonta/114…


#cfw got an org-table import/export functionality. Just select the org-table and run M-x cfw-org-load. Analyse, sort, edit, filter your table in CFW. Then update the original org-table by M-x cfw-org-save.

If there was no original org-table (the table was created from scratch or from other source like CSV), the cfw-org-save places the exported table into the kill-ring. This way org pivottables can be generated from CFW.

#emacs




The seemingly canonical way of detecting whether the C-u modifier was used on an interactive function call (when an actual numerical argument wasn't provided) in #elisp feels... icky. #emacs
in reply to Jonathan Lamothe

To be fair C-u *is* a numerical argument so you're not really meant to differentiate (it means the number 4). 😅
in reply to Alessio Vanni

@Alessio Vanni Yeah, it's just very magic number-ey.

Ah well, such is the way it is with legacy code sometimes. No way to change it without breaking about a billion other things.



Me: I'm just going to specify these #org-mode table formulas so that they can be executed sequentially to update this whole table in a single pass.

org-mode: Hey bro, let me automatically sort those by position for you. You're welcome.

Me: 🤦‍♂️

#emacs



Wrapping my brain around using #org-mode as a spreadsheet. Is there a way to pass a range of cells as a vector to a custom function? Ideally, I'd like to embed this function into the file itself. #emacs
in reply to Jonathan Lamothe

I like using org tables with org-babel like so:

#+NAME: test
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |

#+begin src emacs-lisp :var test=test

(mapcar
'(lambda (r)
(mapcar '(lambda (x) (* x x)) r)) test)

#+end src

#+RESULTS:
| 1 | 16 |
| 4 | 25 |
| 9 | 36 |

Unknown parent

friendica (DFRN) - Link to source
Jonathan Lamothe
@hajovonta You are correct. The ridiculous thing was that I had literally just looked it up. My brain does strange things sometimes.


I wonder how difficult it would be to introduce rudimentary namespaces into #elisp.

#emacs

Harald reshared this.

in reply to Jonathan Lamothe

Just learned about interned vs. uninterned symbols. Feels like this would be a big piece of this puzzle.


I have successfully built my first #Emacs package. I want to clean it up a bit before I consider releasing it though. Also, while I can build a simple (single file) package, buildig a multi-file one is still eluding me.

When I try to install it, I get the following (less than helpful) error message:
Wrong type argument: stringp, nil

Is there a way I can get more detail on why this is failing?

reshared this

in reply to 🇺🇦 Myke

@🇺🇦 Myke Yes, it can be done that way as well.

That still doesn't negate the point that I want to know how to build a multi-file package.

Besides, sometimes I like to learn stuff just for the sake of learning it.



I've been an #Emacs user for like 20 years because there was one thing I needed to do back then that was made easier by elisp, and I just got used to using it. In all that time, I hardly ever tinkered much with the config, save a few minor tweaks it was pretty much stock. I had no strong feelings about Emacs in general, it was just the text editor I'd grown comfortable with.

I've recently been diving into #Lisp and poking around with my Emacs config, and after all these years, I think I'm starting to get the appeal. I am still a proponent of "use the tool that works for you", but I'm personally firmly on team Emacs now.

Julio Jimenez reshared this.

in reply to Jonathan Lamothe

I'd been told that there were add-ons that could do things like making vim more Emacs-like, but I never saw the point in spending energy to make some arbitrary tool more like the one I was already using for no particular reason.


I've been an #Emacs user for probably about two decades. Despite this, I only recently learned that ELPA and MELPA are not the same.

reshared this



Today I somehow fumbled an #org-mode keyboard command and made a file into an attachment on itself. I didn't know that was possible.

Fortunately, revision control came to the rescue.

#emacs #git



Is there a way to tell #Emacs #org-mode to omit yhe TOC and headline numbers when exporting to a text or markdown file? I'm trying to implement a #JohnnyDecimal system, so I'm supplying my own numbers and the 00.00-index.org file essentially is the table of contents.

Edit: Because not all replies federate, here's the solution I ended up with:

#+STARTUP: overview indent nonum
#+OPTIONS: toc:nil
in reply to Jonathan Lamothe

Sorry I don't have an answer. Nonetheless as an Emacs user (albeit only rarely in org-mode) I'll be interested in the responses you get. Cheers, -Randy

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.