Progress Update: Emacs Discourse Integration

Features Implemented
:white_check_mark: Category listing and navigation
:white_check_mark: Topic viewing with proper formatting
:white_check_mark: Reply functionality with markdown support
:white_check_mark: Proper CSRF token handling for API requests
:white_check_mark: Clean buffer management and UI
Current Focus
Working on improving the user experience with:

Better error handling
Intuitive keybindings
Markdown preview support
Topic creation interface
Next Steps
Add topic creation functionality
Implement search capabilities
Add user profile viewing
Support for private messages
Feel free to test it out and provide feedback! The code is available at: glenneth/discourse-emacs: A modern Emacs package for seamless Discourse forum integration. - Codeberg.org this post was made using the glenneth/discourse-emacs: A modern Emacs package for seamless Discourse forum integration. - Codeberg.org branch

1 Like

@Glenneth are all those posts supposed to be four different topics? That seems… Kinda spammy, tbh.

They were separate posts. And yes it was a bit spammy. David has since set me up with a testing area. I was testing new features in my discourse package for creating new topics this morning.

I apologise for the spamming @ashraz

;; Global keymap
(define-key global-map (kbd "C-c d") discourse-command-map)

That violates the key bindings convention for packages. C-c <letter> is reserved for users, see (elisp) Key Binding Convention:

D.2 Key Binding Conventions

===========================

  • Don’t define C-c LETTER as a key in Lisp programs. Sequences consisting of C-c and a letter (either upper or lower case; ASCII or non-ASCII) are reserved for users; they are the only sequences reserved for users, so do not block them.

    Changing all the Emacs major modes to respect this convention was a lot of work; abandoning this convention would make that work go to waste, and inconvenience users. Please comply with it.

Thanks @ashraz. That should be an easy fix. Maybe :rofl:

No worries. I’d just recommend to test your package with a local installation of Discourse. That allows you to also check multi-user experience (e.g. have user Glenneth active in Emacs instance 1 and Troll in Emacs instance 2) without having to ask other users for private messages and/or replies :slight_smile:

That could be a preferable testing environment for sure. I never thought of installing discourse locally for that.

Another easy fix: remove the duplicate functions. discourse--create-topic is defined twice, once in L870, once in L1183.

It’s also a bit weird to see discourse-api-request intermixed with plain request. That will make refactoring (or replacing request with url-retrieve) harder later on.

(I’d comment on Codeberg, but I don’t have an account there, sorry)

@ashraz i’ve changed the discourse command map keybindings in a feature branch for now and also removed the duplicate create-topic function. New keybindings look like this

;; Global keymap
(defvar discourse-command-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "l") 'discourse-login)
    (define-key map (kbd "g") 'discourse-get-categories)
    (define-key map (kbd "t") 'discourse-get-topic)
    (define-key map (kbd "c") 'discourse-create-topic)
    (define-key map (kbd "v") 'discourse-view-topic)
    (define-key map (kbd "r") 'discourse-reply-to-post)
    map)
  "Keymap for Discourse commands.")

(define-key global-map (kbd "C-c C-d") discourse-command-map)
1 Like

That’s a great addition. But: that’s also reserved:

D.2 Key Binding Conventions

  • Sequences consisting of C-c followed by a control character or a
    digit are reserved for major modes.

I’d recommend you to read (elisp) Key Binding Conventions and also go the “usual” way, e.g. instruct your users to set up their own bindings. Both Org mode and Prot’s denote do so in their sample configuration.

Also, that almost looks like you want to have a transient menu. So you might consider using transient and a discourse-menu there instead of a keymap. Speaking of menu, you might also want to tackle an Discourse menu (for menu-bar-mode).