Advertisement · 728 × 90
#
Hashtag
#DoomEmacs
Advertisement · 728 × 90
Today I finally tackled something that has annoyed me for a while since switching most of my editing/digital gardening/second brain-writing over to Emacs.

Whenever I took 30 minutes and tried to get title fetching of links to work, I couldn't get it to work in this self-allotted time. So I asked Opus to do the dumbest thing possible: Just fetch it via curl, and then apply stuff asynchronously.

(Obviously the other, non-dumb way should work too, but I've spent way to much time on this now either way.)  
(And apparently there's also `url-insert-file-contents`, maybe I'gonna try that some other time.)

```elisp
(defun flt--url-at-point ()
  "Get URL at point, or nil."
  (thing-at-point 'url))

(defun flt--url-from-kill-ring ()
  "Get URL from kill ring if it looks like one, or nil."
  (let ((text (current-kill 0 t)))
    (when (and text (string-match-p "\\`https?://" text))
      (string-trim text))))

(defun flt--get-url ()
  "Get URL from point first, then kill ring. Nil if neither has one."
  (or (flt--url-at-point)
      (flt--url-from-kill-ring)))

(defun flt--extract-title (html)
  "Extract <title> content from HTML string."
  (when (string-match "<title[^>]*>\\([^<]*\\)</title>" html)
    (string-trim (match-string 1 html))))

(defun flt--insert-markdown-link (url title marker)
  "Replace URL at MARKER with a markdown link, or insert at MARKER."
  (with-current-buffer (marker-buffer marker)
    (save-excursion
      (goto-char marker)
      ;; If there's a raw URL at point, replace it
      (let ((url-bounds (thing-at-point-bounds-of-url-at-point)))
        (if url-bounds
            (progn
              (delete-region (car url-bounds) (cdr url-bounds))
              (insert (format "%s" title url)))
          (insert (format "%s" title url)))))))

(defun flt-fetch-link-title ()
  "Fetch the title of a URL (at point or kill ring) and insert a markdown link.
If point is on a URL, replaces it. Otherwise inserts at point."
  (interactive)
  (let ((url (flt--get-url)))
    (if (not url)
        (message "No URL found at point or in kill ring.")
      (let ((marker (point-marker))
            (buf (generate-new-buffer " *flt-curl*")))
        (message "Fetching title for %s..." url)
        (make-process
         :name "flt-curl"
         :buffer buf
         :command (list "curl" "-sL" "-m" "10"
                        "-H" "User-Agent: Emacs"
                        "--" url)
         :sentinel
         (lambda (proc _event)
           (when (eq (process-status proc) 'exit)
             (let ((title
                    (with-current-buffer (process-buffer proc)
                      (flt--extract-title (buffer-string)))))
               (if title
                   (progn
                     (flt--insert-markdown-link url title marker)
                     (message "Inserted: %s" title url))
                 (message "Could not extract title from %s" url)))
             (kill-buffer (process-buffer proc))
             (set-marker marker nil))))))))

(map! :leader
      :desc "->title" :nv "d f" #'flt-fetch-link-title)
```

And in the meantime, I also learned that _markers_ exist!

So now, I can fetch link titles again, like I'm used to :)

Today I finally tackled something that has annoyed me for a while since switching most of my editing/digital gardening/second brain-writing over to Emacs. Whenever I took 30 minutes and tried to get title fetching of links to work, I couldn't get it to work in this self-allotted time. So I asked Opus to do the dumbest thing possible: Just fetch it via curl, and then apply stuff asynchronously. (Obviously the other, non-dumb way should work too, but I've spent way to much time on this now either way.) (And apparently there's also `url-insert-file-contents`, maybe I'gonna try that some other time.) ```elisp (defun flt--url-at-point () "Get URL at point, or nil." (thing-at-point 'url)) (defun flt--url-from-kill-ring () "Get URL from kill ring if it looks like one, or nil." (let ((text (current-kill 0 t))) (when (and text (string-match-p "\\`https?://" text)) (string-trim text)))) (defun flt--get-url () "Get URL from point first, then kill ring. Nil if neither has one." (or (flt--url-at-point) (flt--url-from-kill-ring))) (defun flt--extract-title (html) "Extract <title> content from HTML string." (when (string-match "<title[^>]*>\\([^<]*\\)</title>" html) (string-trim (match-string 1 html)))) (defun flt--insert-markdown-link (url title marker) "Replace URL at MARKER with a markdown link, or insert at MARKER." (with-current-buffer (marker-buffer marker) (save-excursion (goto-char marker) ;; If there's a raw URL at point, replace it (let ((url-bounds (thing-at-point-bounds-of-url-at-point))) (if url-bounds (progn (delete-region (car url-bounds) (cdr url-bounds)) (insert (format "%s" title url))) (insert (format "%s" title url))))))) (defun flt-fetch-link-title () "Fetch the title of a URL (at point or kill ring) and insert a markdown link. If point is on a URL, replaces it. Otherwise inserts at point." (interactive) (let ((url (flt--get-url))) (if (not url) (message "No URL found at point or in kill ring.") (let ((marker (point-marker)) (buf (generate-new-buffer " *flt-curl*"))) (message "Fetching title for %s..." url) (make-process :name "flt-curl" :buffer buf :command (list "curl" "-sL" "-m" "10" "-H" "User-Agent: Emacs" "--" url) :sentinel (lambda (proc _event) (when (eq (process-status proc) 'exit) (let ((title (with-current-buffer (process-buffer proc) (flt--extract-title (buffer-string))))) (if title (progn (flt--insert-markdown-link url title marker) (message "Inserted: %s" title url)) (message "Could not extract title from %s" url))) (kill-buffer (process-buffer proc)) (set-marker marker nil)))))))) (map! :leader :desc "->title" :nv "d f" #'flt-fetch-link-title) ``` And in the meantime, I also learned that _markers_ exist! So now, I can fetch link titles again, like I'm used to :)

Async Link Fetching in Emacs

#TIL #Emacs #DoomEmacs

0 0 2 0
Original post on aleph.land

I'm considering apostatizing from the church of #emacs. the original allure was, for everything you want to do... "emacs has a package for that." that largely seems to hold up.
but.

#doomemacs manages the whole dependency graph for me, which is pretty great. Except when it fails. I made an […]

0 0 0 0

#Fedora does not support #doomemacs
#Cosmic does neither support middle mouse paste nor japanese/anthy input
#Sway ignores input switch configuration completely

0 0 0 0

#Fedora does not support #doomemacs
#Cosmic does neither support middle mouse paste nor japanese/anthy input
#Sway ignores input switch configuration completely

0 0 0 0

Jakou nejdelší klávesovou zkratku/posloupnost běžně používáte ve svém editoru/IDE?

U mě to je asi:

"C-c n r d T" - org-roam-dailies-capture-today

#emacs #doomemacs

0 0 1 0

There are 2 things that I don't like in life:

1. abstractions in config code (sorry #doomEmacs)
2. abstractions in test code

When I start thinking myself into the test setup to make the damn thing green, my fingernails are crawling upwards.

#software #softwareEngineeringLife

1 0 0 0
A screenshot of my game development desktop

A screenshot of my game development desktop

The game development environment. #emacs #doomemacs #c #cgdb #sdl #btop #linux #gamedev #indiegamedev

14 2 1 0
Original post on aleph.land

joining the church of #emacs (via #doomemacs )...

#magit just isn't as good as #sublimemerge. I can't deny it. which means, I intend to go forward using tools *outside* of emacs, and will never *truly* join the cult.
but that's fine. emacs insists it's a text editor as opposed to an IDE.
...i […]

0 0 0 0

Terrible if you are prone to diving down rabbit holes of configuration and tinkering. Awesome if you love the idea of a text-based ecosystem, but want to ease into emacs gently.

I've loved it!

#emacs #doomemacs

0 0 0 0
Original post on aleph.land

I'm learning #emacs (specifically #doomemacs). so far it's a delight. (so far i've written 0 lines of code.)

psa, if you happen to be like me. i.e., a refugee from the ruins of visual studio's former glory:

1) get out of the habit of "open the project file and look around". get in the habit of […]

0 0 0 0

Dum kelka monati me uzis #doomemacs, ma pokope me ne volis uzar ol plu. Nun mi volas uzar emacs sole, tale me povas lernar komo uzar ol bone.

#idoLinguo #ido

2 0 1 0

I've decided to retire the emacs config I've been working on for the past 7 years in exchange for Doom Emacs 🥲 #emacs #doomemacs

0 0 0 0
Preview
GitHub - doomemacs/doomemacs: An Emacs framework for the stubborn martian hacker An Emacs framework for the stubborn martian hacker - doomemacs/doomemacs

There need not be a war. There is #spacemacs and #doomemacs
Everyone is happy. #youdoyou
https://github.com/doomemacs/doomemacs

0 0 0 0

The great thing about using Doom Emacs or any evil mode editor at work is that you really don’t need to worry about regular people snooping on your stuff because the interfacing is password protection enough #emacs #doomemacs #orgmode

1 0 0 0
Post image

#DoomEmacs :lang section 🤣

0 0 0 0