Showing 589 to 592

Problem: Eshell assumes no multiline prompt

Offenders

  • eshell-bol
    • Try typing M-p (eshell-previous-matching-input-from-input) on a multiline prompt. The misbehavior is because that function above does not handle multilines
  • eshell-prompt-initialize
    • It disregards the Custom variable eshell-skip-prompt-function, overriding it in favor of the builtin eshell-skip-prompt, which does not handle multilines
  • Probably other things

What links here

Created (10 months ago)

Consensus-tournament

Suppose you wanted to maximize consensus, so you have consensus-based democracy instead of winner-takes-all democracy.

What if you had a system whereby

  • the entire population pairs up randomly for one-on-one dialogue
  • once a pair reaches some consensus/compromise, the pair agree on who will speak for them both on stage 2
  • on stage 2, we're down to half the population, right? this half pairs up and repeats the process
    • and perhaps the speakers-for-the-pair are accompanied by their counterpart, who just listens to check that the speaker is not misrepresenting their consensus

What links here

  • Democracy
Created (10 months ago)

Svelte: Redirect to new page ID

Suppose

  • that your website has page IDs in the sense of domain.com/PAGEID/slug. For example, you're probably seeing this very page at the address edstrom.dev/csbxq/redirect-to-new-page-ids-in-sveltekit, so the ID is csbxq.
  • that you update the ID to use new algorithm, so now it's going to be 6uXpfOI2c9fJdh2aa22. Time to set up a redirect!

I'll assume your page's loader (the file you've got on a path like src/routes/[id]/[[slug]]/+page.js) contains this:

import { error } from '$sveltejs/kit'
import posts from '$lib/posts.json'

export function load({ params }) {
    let post = posts[params.id]
    if (post) return post
    
    error(404, "Not found")
}

Edit that to something like this.

import { error, redirect } from '$sveltejs/kit'
import posts from '$lib/posts.json'
import v1_to_v2 from '$lib/v1_to_v2.json' // assumed a table of old and new ID

export function load({ params }) {
  let post = posts[params.id]
  if (post) return post

  // Redirect from v1 to v2 id
  let idv2 = v1_to_v2[params.id]
  if (idv2) redirect(308, `/${idv2}`)
  
  error(404, "Not found")
}

This assumes that navigating to just domain.com/IDV2 is satisfactory.

To also include the slug in the redirection (remember the slug in domain.com/PAGEID/slug?), I'll assume your post object contains metadata post.id and post.slug and then we can do the redirection like this:

// ...
export function load({ params }) {
  let post = posts[params.id]
  if (post) return post

  // Redirect from v1 to v2 id
  post = posts[v1_to_v2[params.id]]
  if (post) redirect(308, `/${post.id}/${post.slug}`)

  error(404, "Not found")
}
Created (10 months ago)

Smart tabs in 2024

There is an old little-used #emacs package for smart tabs. All the languages it supports:

(require 'smart-tabs-mode)
(smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby 'nxml)
(add-hook 'c-mode-common-hook #'indent-tabs-mode)
(add-hook 'java-mode-hook #'indent-tabs-mode)
(add-hook 'js2-mode-hook #'indent-tabs-mode)
(add-hook 'cperl-mode-hook #'indent-tabs-mode)
(add-hook 'python-mode-hook #'indent-tabs-mode)
(add-hook 'ruby-mode-hook #'indent-tabs-mode)
(add-hook 'nxml-mode-hook #'indent-tabs-mode)

Not much, is it? But that's ok, this way to do it has always been somewhat doomed.

Let's say you share a codebase with people on different platforms. It's not as if you can tell a VSCode person to install the above Emacs-Lisp package.

Autoformatters like gofmt do smart tabs for you these days, and when you can't mandate an autoformatter, the standard way to prevent chaos has been a "spaces only" rule. Maybe when we get an .editorconfig rule for smart tabs (issue 323), this can change?

(Once that's finalized, then Emacs is gonna need a new way more general smart-tabs-mode! Probably based on tree-sitter.)

As far as I can figure, "spaces only" must have been the pragmatic option since the dawn of computing, but maybe the innovations of tree-sitter and editorconfig finally make tabs a real option.


Someone points out that editorconfig's indent_style = tabs rule actually makes no sense if it's not smart tabs anyway, so it shouldn't exist. Makes you think who was using that rule before…

I.e. the choices are:

  • Spaces only: OK
  • Smart tabs: OK
  • Tabs only, used as "wide spaces" assuming they will be rendered at a specific width: no
Created (10 months ago)
Showing 589 to 592