Emacs org-mode

Welcome to the Emacs org-mode category.

You can subscribe to this category only via RSS!

I am working on restoring some of my related posts from my old blog, so keep checking here for new content.

Auto-generated description: A mythical creature resembling a satyr with glasses is sitting cross-legged in a forest setting, holding a glowing orb in front of a laptop.

    Launching a script with a keyboard shortcut on a Mac?

    I wanted to try out Eamcs Everywhere for a while, and today I finally took the plunge. The package is on Melpa, so installing it was a breeze, and it worked straight out of the box. The problem, as it turns out, is to get macOS to run the needed command (a script) with a keyboard shortcut.

    The idea behind Emacs Everywhere is simple. When you visit a non-Emacs text window on your Mac (say you want to post something on blue sky or Reddit, perhaps answer an email from Mail), you invoke an Emacs frame and write whatever you need. Then, with C-c C-c, just like a capture template, you close that window, and the text you wrote in that Emacs frame is copied into the window you have open. It basically saves you a couple of copy-pastes.

    I spent some good time researching how to get a keyboard shortcut to run a script. Most recommendations on the package itself recommend using a third-party app like Alfred, of which I’ve heard many good things. But I don’t want to get yet another app just to have an experimental Emacs package going.

    The traditional macOS way seems to involve Automator. You create workflow in there, create the script (it’s just "emacsclient --eval '(emacs-everywhere)'" - oh and yes, it does require you have Emacs server running, which I do) and then call this workflow as a service from MacOS’s keyboard shortcuts, under settings. The problem there is that I don’t see the workflow I created. I know it’s saved, because if I right-click somewhere to open the menu and choose “services,” I do see it, but it just doesn’t show under my keyboard shortcuts.

    I also asked the sage advice of JCS from Irreal, who directed me in the direction of icanhazshortcut. I like the look of this one: it’s an app with the single purpose of creating keyboard shortcuts to do different things - just what I need. But it doesn’t seem to work either - it simply crashes whenever I launch the shortcut I created. It doesn’t look like this app has been updated in a couple of years, so it’s possible some new macOS security feature blocks it somehow.

    I’m surprised it’s so challenging to create a custom shortcut on a Mac that will just run a script. It’s the very basic of automation in my opinion. I’m probably missing something simple.

    Harper: quick, light and private grammer check for Emacs

    I got some time to spend with Harper, a “free English grammar checker designed to be just right,” which can be integrated into Emacs.

    Before I proceed, I want to note that while the description on the website from the creator states, “you can think of it as an open-source alternative to Grammarly,” I find this to be misleading. At least on Emacs on my Mac, Harper does not compare to what I get from my premium account on Grammarly1.

    Still, if you’re looking for something free, open source, private, and fast, you should check out Harper.

    To get Harper to work on a Mac, you want to install it from Homebrew, as the documentations show: brew install harper. Then for Emacs, Harper uses harper-ls, which is the Language Server Protocol server (LSP) for Harper. This is something that tripped me earlier: on Emacs, you do not interact with Harper directly, but with Emacs’ built-in client for LSPs, Eglot, instead. Confused? I sure was. The part to remember is that we’re going to run M-x Eglot commands when we interact with Harper on Emacs.

    A diagram would look something like this: Emacs > Eglot (LSP Client) > harper-ls (LSP Server) > Harper.

    To configure Eglot to recognize and run with Harper’s LSP server, harper-ls, we can add the basic configuration to our Emacs init as described in Harper’s documentation, with a minor adjustment:

        (with-eval-after-load 'eglot
          (add-to-list 'eglot-server-programs
                       '(org-mode . ("harper-ls" "--stdio"))))
    

    I’ve added the org-mode part instead of text-mode as described originally because I want Harper to work in org-mode. The credit for this goes to Jakub, who wrote about this in his blog and was also kind enough to email me directly and explain things even further when I was confused; so thanks Jakub! You’re alright in my book.

    Jakub is from Australia, so he included a dialect option for Australian and a hook to launch eglot when org-mode is loaded, so that he wouldn’t need to launch it manually. Check his config in the link above with his explanations.

    I changed my config’s dialect to American, as an option described in the documentation. After some time with Harper, I also decided to remove the org-mode hook because Harper will happily mark everything that looks like a mistake in org-mode buffers. This includes the agenda, checklists, code segments, etc.2. I also prefer to separate my editing from my writing, as I find these green zigzags distracting.

    When I launch Harper in org-mode with Eglot, it looks like this:

    Auto-generated description: A computer screen displays a text editor terminal with highlighted syntax, showing lines of written code and text.

    As you can see in the picture, I ran Harper on the draft of this post. It delimits every line with an issue with an exclamation point, then highlights the error with a green zigzag. When you hover over the grammatical error with the point (or the mouse cursor), Harper displays the error in the mini-buffer. In the case above, it lets me know I have a sentence that is too long.

    You can correct mistakes directly with Harper by utilizing the correct Eglot commands (remember that you have to “talk” to Eglot to work with Harper). For example, you can use its Code Actions with eglot-code-actions, which will display a menu of available fixes to replace your text with. I’m quickly learning I should probably get a shortcut for this because I’m going to use this plenty. There are other aspects of Harper I’m still learning about; it comes with additional tweaks and configurations, including user dictionaries.

    All in all, Harper does a decent job of catching most grammatical errors and spelling mistakes. However, I still find that I need to pass the text through Grammarly to catch some errors. For example, in this very post, the line where I wrote “It delimits every line with an issue…” was “It delimiters every line…” and Harper was okay with it. Harper also seems to miss my plural confusions, for example, “as an option described in the documentations,” is fine with Harper, but it should be “as an option described in the documentation.” Then there’s where, in my opinion, Grammarly shines next to other LLMs: style suggestions. I can ask Grammarly to make a part of the text shorter, more professional, more friendly, etc., and it will do so on the spot. Chat GPT and the like can do the same thing, but you have to do several copy-pastes to get to the same result, and even then, I find it’s not quite as polished. It’s also helpful to always have these versions in front of you so you can choose the style you want. Grammarly also highlights the errors it finds in different colors: definite issues will be in red, while suggestions for style will be in blue.

    Many people don’t need this level of a “grammar nanny,” and I totally understand what Harper’s developers mean when they say Grammarly is overbearing. Add to that the fact that Grammarly sends all your private Emacs notes to the Grammarly servers, where they can do whatever they want with them, complete with the premium cost and… yeah, I totally get it. Meanwhile, Harper does most of the works, and fast, especially when compared to languageTool, which also requires you to install Java and deal with its weird updates. Oh, and those of you who use Obsidian: Harper has an official plugin, which I suspect works even better than what I wrote about here.

    Give it a try, and if you’d like, let me know what you think. Meanwhile, I will see if I can make it my go-to grammar tool on my Linux Desktop.

    Footnotes

    1 : I get Grammarly through work. If that weren’t the case, I’m not so sure I’d rush to pay for it myself, which comes close to $30 a month.

    2 : The reason Harper doesn’t know to ignore the org-mode syntax option for code (words between ~ ~) or other special characters is because org-mode is not yet officially supported. When this happens, I guess these issues will go away and I will try to launch Harper with a hook for org-mode again.

    Installed Emacs again on Pop OS (I wiped it after my GPU issues), and now I realize I’ve had this weird issue in org-mode, where images are displayed in landscape mode. Some of my images are rotated 90 degrees in the wrong direction. Anyone familiar with this, what causes it, and how to fix it?

    Discovered Harper in this blog post but not sure how to get it to work. Installed with homebrew, evaluated the default lisp they have on their site and… ok, now what? I don’t see any Harper-related commands. Has anyone figured it out?

    Short version: Harper is a frontend to Server Language Protocol (SLP). Emacs has a built-in SLP called Eglot. This means you use Eglot on Emacs to run Harper, so the interactive (M-x) command is Eglot (and it helps if you spell it correctly 🤦‍♂️). The E-Lisp configuration they have on their website (above) works fine, provided Eglot is configured to run and you have Harper installed.

    I will expand later after I experiment some more.

    Adjusting my org-mode workflow

    One of the things that affects my workflow at work and Emacs recently is the source of my tasks and projects.

    In the past, I worked almost exclusively with our ticketing system. My capture templates in org-mode contained properties for ticket numbers and user IDs to identify the users. Each task in org-mode I created this way included a scheduled date for that day, which I would move around later, depending on urgency.

    This all went away when I moved to a more managerial position about a year ago, but it took me some time to realize that. My new position means that roughly 80% of my projects come from Emails while the rest come from meetings. I almost never have a ticket assigned to me directly, unless it has to do with my old position as a tech writer, which I still do now and then1.

    Habits die hard, and I was trying to fit email chains and meeting notes into my task templates in org-mode with limited success. For example, I was struggling to figure out what properties I need, since emails don’t really point a user with a problem, but often describe a situation that requires a solution.

    Meanwhile, I was swapped away by Journelly (and for a good reason) and started to use it in meeting notes, but realized that I tend to keep these notes in a certain manner that would fit nicely into a capture template. These notes, which consisted mostly of bullet points and questions, did not fit well visually with the rest of the journal. More so, since I often write down things to do in meetings, I needed an indicator to flag those meetings later, when I need to go through the notes and re-write those as tasks2. This quickly became cumbersome.

    For my meetings then, I created this simple template (for more structured templates, I use org files rather than writing them directly into my settings):

        * MEETING %?
        %^T
        
        *Discussion:*
        -
        
        
        *To Ask:*
        -  
        
        
        *To Do:*
        - [ ] 
    

    I write the points in the meetings as people discuss them. As I listen, I come up with questions/comments which go below (I tend to write the answers as nested items below the questions with a “+” rather than a “-” to indicate an answer). The To Do part is newer, usually containing large items (projects) that need to be broken down further into dedicated tasks. This is still a work in progress.

    As for emails, I still don’t have something solid. I mostly rely on my existing project template, but it doesn’t fit as nicely as the meeting template above.

    Emails in Outlook are usually a mess of “conversations” by the time I get to read them. I then need to spend time on reading and understanding what’s going on, which is often an issue in itself, as people require urgent answers for complicated matters (Emacs is amazing, but I don’t think it can help me with that). I was looking into a way to identify emails by their email ID and use these as properties, but this is something that can only be done on the back end, which I don’t have access to. I probably need to spend more time with Outlook and its filters, and that’s a mess in itself, as Microsoft tends to change options and controls across its different versions. If anyone reading this has any advice, I’m all ears.

    Ideally, Emacs projects stemming from emails should contain the email subject or another identifier (ideally in the header itself), then the people involved (the askers and the doers), location, and then resulting ticket numbers for the tasks created - but this is all flexible.

    Footnotes

    1 : interestingly, my experience writing technical documents is helpful when I need to delegate work or explain a workflows in meetings - and org-mode is one of the best place I ever had to write such documents because it is an outline tool that breaks processes to steps by default.

    2 : For about a week, I used Journelly’s tagging system to tag certain notes as meetings, which helped me realize how ridiculous this was. Journelly is a place for me to see pictures of people I spent time with or capture ideas when I get a chance to stop and think a little, often by dictation. Meetings are nothing like these things, and they shouldn’t. It’s easy for me to write now, clear as day, but a few weeks ago I didn’t know.

    compressing mp4 files while keeping better quality with dwim in Emacs

    I mentioned Rameriez’s dwim tools, and it’s only natural to do some IT for fun when I rest from IT at work on the weekend, Right…? Eh, don’t answer that.

    One of the important and excellent things about Rameriez’s package is that it makes it easy to build something custom of your own using the “Lego blocks” he provided with the package.

    For example, one of the commands that comes with the package is dwim-shell-commands-resize-video, which lets you resize the resolution of a video (and through that, its size). It does the job well, but I wanted something that compresses videos while retaining their resolution for quality. I know how to do this directly with ffmpeg, so I thought I’d give dwim a go, and got something working pretty quickly:

        (defun jtr/dwim-shell-command-compress-mp4-fast ()
          "Compresses mp4 down further using slow preset."
          (interactive)
          (dwim-shell-command-on-marked-files
           "Compresses MP4s with libx265 using slow preset to bring down size"
           "ffmpeg -i '<<f>>' -c:v libx265 -crf 25 -preset slow '<<fne>>_compressed.mp4'"
           :utils "ffmpeg"))
    

    There are a couple of things at work here with ffmpeg:

    First, libx265, which is a newer decoder than the default libx264. The newer version does a better job at retaining video quality when compressing, but at the cost of compatibility; some older systems might not be able to play the resulting MP4 file or say there’s something wrong with it until you install the needed decoder. If you’re playing with ffmpeg regularly, you probably won’t have a problem - but the people you send these videos to might, so keep that in mind.

    Second, the slow preset. This increases the time it takes ffmpeg to work on the video as it combs through the frames more carefully. I forget exactly what it does, but I believe it grabs a smaller group of frames each time, so more frame groups (hence more time) with different compression values.

    Lastly, the CRF value is at 25, a bit less than the default 28 for libx265, so a bit less compression. I can probably push it up a bit further, but the above already reduces the file size dramatically.

    Journelly is having me try a new perspective

    A couple of people wrote back to me regarding my last post about the challenges I have with Journelly (which, again, don’t really have anything to do with the app itself, but my workflow).

    In an Email, HTH let me know that while Syncthing is not officially supported on iOS, there is an app that works and does the job just fine: SyncTrain. I tested it, and it successfully synced my files to my iPhone, iCloud not included. That’s an amazing find.

    Meanwhile, I was thinking about how I can better streamline my process of refiling Journelly’s entries to my journal, where they are… archived. Duh! I can simply use org-mode to archive entries into my journal file. All I need to do is define the file I want them to archive into in the file options at the start of the file. Journelly even has an archive feature built in, but since I want to save my entries off the phone, it won’t work for me.

    However, I realized I might not want to send my Journelly entries away. Journelly is convenient, and I use it constantly for notes. Having these available on my iPhone (where Journelly has an excellent search feature with tags) and on Emacs on the Mac at the same time is a boon to my productivity, not to mention, it just looks so nice on the phone.

    So now I’m considering a different mental approach. Instead of refiling and moving entries away from Journelly, I’m going to try and expand on what I have there later. Some of this I already discussed before: things like meeting entries, for example, can be copied later to my dedicated meeting file, and activities can be copied to my event file, if I feel there’s more to add. The missing piece is expanding on “mind dumps” in Journelly that go into tangents. For that, I want to break the ideas into specific subjects with Denote later. For example, if I write an entry in the morning about Journelly and I’m realizing I’m rambling about the app and have ideas, I can later put these ideas into a “Journelly thoughts” note later with Denote, along with the appropriate keywords and attachments, as needed. This, I think, also covers the concern I have regarding privacy and iCloud, as the Journelly entry will just cover the initial nugget, where I will write some key points which I will later develop in a dedicated note off Apple’s servers.

    This is all pretty new and raw in my head, so I’m going to try that out for the rest of the week and see how I feel.

    I wish I could use Journelly's new location features, but...

    Journelly keeps getting updated with good features. One of the latest features I noticed (I’m not sure if it was part of the latest patch) is that locations tagged with entries can be revisited in iOS Maps from the app. This makes Journelly a good spot to save locations and integrate them with personal memories, to be revisited later on the map. I would like to use this (instead of, say, a saved of locations on Google Maps), but I can’t - for two reasons.

    The first one, which I can work around, is that the list of entries on Journelly quickly becomes long, and finding where you were a couple of weeks ago requires some scrolling. While Journelly has a search option, I usually don’t remember the name of the place I’m searching for, which is why I’m searching for it in the first place. Still, I could probably look for who I was with at the time, or even better, use the tagging feature, which was introduced a couple of weeks ago, for, say, “#cafes” to filter down cafes only.

    The other issue is more challenging: I don’t keep my notes in Journelly. I keep refiling my entries into my main journal file. That file, while still on my Mac, is not synced with iCloud. Call me paranoid, but I don’t trust Apple’s iCloud with my personal notes along with my pictures throughout the years. As far as I’m concerned, Apple just has a better PR department than Google and Microsoft, and they only care about their users’ privacy as long as it’s what looks good in the news. Because of that, I am not comfortable with Journelly being my archive of notes. There could be other options besides iCloud, but as far as I know, they all involve a cloud company somewhere. On Android and macOS, I still use the excellent Syncthing, which doesn’t involve any cloud storage. However, Syncthing doesn’t work on iOS, so I’m out of luck.

    Besides these two issues (which have nothing to do with the app), the app is terrific. It’s amazing how polished and responsive it is.

    Coffee time. I woke up wondering about .org-id-locations. You know, that Emacs file that keeps track of all of your org-mode IDs. How does it know where are the headers in the files it refers to? Is there a size limit? Can I use a different file (or files) if I want to for the hell of it?

    What?? Don’t look at me like that. I often think about Emacs just before I fall asleep and when I wake up. Don’t you?

    A hand is holding a coffee cup with the Emacs logo near a window, c clouldy rainy day outside

    Two Eamcs tweaks I forgot about (most of you will know these):

    Use Consult’s recentf to see a list of files that were edited recently:

      (global-set-key (kbd "C-x C-r") 'consult-recent-file)
    

    Consult’s org-agenda (jump to heading) is quicker than what I usually do, which is to list all ACTIVE keywords in emacs (this is how I list my projects), and then go down the tree to find the specific TODO header I want.

    Since I often know what I’m looking for within active projects, I can use consult-org-agenda, which narrows headers dynamically as I search. Much faster and clutter-free:

      (global-set-key (kbd "C-c C-h") 'consult-org-agenda)
    
← Newer Posts Older Posts →