2019-07-15 Emacs news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the Emacs NEWS file and emacs-devel.

Tweaking Emacs on Android via Termux: xclip, xdg-open, syncthing conflicts

Update: Fixed reference to termux.properties

I’m planning to leave my laptop at home during our 3-week trip, so I’ve been shifting more things to my phone in preparation. Orgzly is handy for reviewing my agenda and adding items on the go, but nothing beats Emacs for full flexibility. Runnng Emacs via Termux works pretty well. I can resize by pinch-zooming, scroll by swiping, and even enter in more text by swiping right on the row of virtual keyboard buttons.

Here’s what I’ve configured in ~/.termux/termux.properties:

extra-keys = [['ESC','/','-','HOME','UP','END','PGUP','F5'],['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN','F6']]

and here’s what that looks like:

Screenshot of Emacs

I patched my Termux to allow the use of function keys in the extra keys shortcut bar. It’s been merged upstream, but the new version hasn’t been released yet, so I’m still running the one I compiled from source. It would be nice to fix accidental keypresses when swiping extra keys to get to the input field, but that can wait a bit.

I set up Syncthing to synchronize files with my server and laptop, Termux:API to make storage accessible, and symlinks in my home directory to replicate the main parts of my setup. I set up Orgzly to auto-sync with a local repository (synchronized with my server and laptop via Syncthing) and the same Org files set up in my agenda in Emacs on Termux. That way, I can hop between Orgzly and Emacs as quickly as I want. Here are a few tweaks that made Emacs even better.

First, a little bit of code for phone-specific config, taking advantage of the weird automatic username I have there.

(defun my/phone-p ()
  (and (equal (system-name) "localhost") 
       (not (equal user-login-name "sacha"))))

For Emacs News, I wanted to be able to easily open Org Mode links to webpages by tapping on them. This code makes that work (and in general, anything that involves opening webpages):

(setq browse-url-browser-function 'browse-url-xdg-open)

This piece of code cleans up my Inbox.org file so that it’s easier to skim in Orgzly. It archives all the done tasks and sorts them.

     (defun my/org-clean-up-inbox ()
       "Archive all DONE tasks and sort the remainder by TODO order."
       (with-current-buffer (find-file my/org-inbox-file)
         (my/org-archive-done-tasks 'file)
         (goto-char (point-min))
         (if (org-at-heading-p) (save-excursion (insert "\n")))
         (org-sort-entries nil ?p)
         (goto-char (point-min))
         (org-sort-entries nil ?o)

     (defun my/org-archive-done-tasks (&optional scope)
       "Archive finished or cancelled tasks.
SCOPE can be 'file or 'tree."
        (lambda ()
          (setq org-map-continue-from (outline-previous-heading)))
        "TODO=\"DONE\"|TODO=\"CANCELLED\"" (or scope (if (org-before-first-heading-p) 'file 'tree))))

I also sometimes wanted to copy and paste between Termux and Emacs by using the keyboard, so I submitted a patch for xclip.el so that it would detect and work with termux-clipboard-get/set. That code is now in xclip 1.9 in ELPA, so if you M-x package-install xclip, you should be able to turn on xclip-mode and have it copy and paste between applications. In my config, that looks like:

(when (my/phone-p)
  (use-package xclip :config (xclip-mode 1)))

Because I use Orgzly and Termux to edit my Org files and I also edit the files on my laptop, I occasionally get synchronization errors. I came across this handy bit of code to find Syncthing conflicts and resolve them. I just had to change some of the code (in bold below) in order to make it work, and I needed to pkg install diffutils to solve the diff errors. Here’s the fixed code below, along with a convenience function that checks my Orgzly directory:

(defun my/resolve-orgzly-syncthing ()
  (ibizaman/syncthing-resolve-conflicts "~/cloud/orgzly"))

(defun ibizaman/syncthing-resolve-conflicts (directory)
  "Resolve all conflicts under given DIRECTORY."
  (interactive "D")
  (let* ((all (ibizaman/syncthing--get-sync-conflicts directory))
        (chosen (ibizaman/syncthing--pick-a-conflict all)))
    (ibizaman/syncthing-resolve-conflict chosen)))

(defun ibizaman/syncthing-show-conflicts-dired (directory)
  "Open dired buffer at DIRECTORY showing all syncthing conflicts."
  (interactive "D")
  (find-name-dired directory "*.sync-conflict-*"))

(defun ibizaman/syncthing-resolve-conflict-dired (&optional arg)
  "Resolve conflict of first marked file in dired or close to point with ARG."
  (interactive "P")
  (let ((chosen (car (dired-get-marked-files nil arg))))
    (ibizaman/syncthing-resolve-conflict chosen)))

(defun ibizaman/syncthing-resolve-conflict (conflict)
  "Resolve CONFLICT file using ediff."
  (let* ((normal (ibizaman/syncthing--get-normal-filename conflict)))
     (list conflict normal)
     `(lambda ()
       (when (y-or-n-p "Delete conflict file? ")
         (kill-buffer (get-file-buffer ,conflict))
         (delete-file ,conflict))))))

(defun ibizaman/syncthing--get-sync-conflicts (directory)
  "Return a list of all sync conflict files in a DIRECTORY."
  (directory-files-recursively directory "\\.sync-conflict-"))

(defvar ibizaman/syncthing--conflict-history nil 
  "Completion conflict history")

(defun ibizaman/syncthing--pick-a-conflict (conflicts)
  "Let user choose the next conflict from CONFLICTS to investigate."
  (completing-read "Choose the conflict to investigate: " conflicts
                   nil t nil ibizaman/syncthing--conflict-history))

(defun ibizaman/syncthing--get-normal-filename (conflict)
  "Get non-conflict filename matching the given CONFLICT."
  (replace-regexp-in-string "\\.sync-conflict-.*\\(\\..*\\)$" "\\1" conflict))

(defun ibizaman/ediff-files (&optional files quit-hook)
  (lexical-let ((files (or files (dired-get-marked-files)))
                (quit-hook quit-hook)
                (wnd (current-window-configuration)))
    (if (<= (length files) 2)
        (let ((file1 (car files))
              (file2 (if (cdr files)
                         (cadr files)
                        "file: "
          (if (file-newer-than-file-p file1 file2)
              (ediff-files file2 file1)
            (ediff-files file1 file2))
          (add-hook 'ediff-after-quit-hook-internal
                    (lambda ()
                      (setq ediff-after-quit-hook-internal nil)
                      (when quit-hook (funcall quit-hook))
                      (set-window-configuration wnd))))
      (error "no more than 2 files should be marked"))))

If you use Emacs on Android via Termux, I hope some of these tweaks help you too!

2019-07-08 Emacs news

Links from reddit.com/r/emacs, /r/orgmode, /r/spacemacs, /r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the changes to the Emacs NEWS file, and emacs-devel.

Weekly review: Week ending July 5, 2019

  • Kaizen
    • Thanks to W-‘s tips, I found it much easier to hang up my bicycle on a hook.
    • W- built legs for the cabinet at the front.
    • I reglued part of the organizer. Since the 90-degree clamps couldn’t fit, I clamped it together using a couple of blocks.
    • I’m pleased with the evolution of my coding skills. I think I’ve gotten the hang of async, and my markup conversion functions even have Mocha tests.
  • Us
    • I hopped on my bike to do some errands.
    • We went for a bike ride. That was pleasant!
    • W- and I enjoyed homemade cake with homemade ice cream.
    • My neck was a little sore from working on the computer.
  • Field trip
    • I took A- to Home Hardware and Creatron so that we could get motors, gears, and a battery case for the ATM project. A- clutched her yellow dual-shaft motor all the way to E-‘s house.
  • Gross motor
    • A- really liked riding on my shoulders as we walked through the neighbourhood. I figured she was still getting balancing practice.
    • The babysitter took A- to the little zoo and playground.
    • The babysitter turned a large sheet of cardboard into a skee ball arcade game.
  • Language
    • A-: “Can I get a Mason jar? With a straw?” Me: “How does it fit?” A-: “Perfectly well.”
    • “We have to tidy up for the babysitter. Otherwise, the babysitter will see a mess. I want even the boys to clean up,” A- said, telling W- to put things away too.
    • We were saying goodbye to E-. He said, “No bye bye! No bye bye!” A- said, “Yes bye bye! I have to go home.”
  • Music
    • While having a bath, A- made up her own version of Hush Little Baby, Don’t Say a Word. My favourite lines: “If it breaks, don’t say anything.” “If you push the donkey, it may hurt.”
  • Emotion
    • A- climbed over my arm several times. As she did so, she said, “Brave A-.” She alternated that with sitting on my laptop and saying, “Scared A-.”
    • I absentmindedly hung my pants on the towel hook. When I returned to the bathroom with A-, she found that hilarious.
  • Household
    • A- was curious about the hand plane and the drill press. She also practised using the power driver.
    • A- helped W- unclog the drain.
    • A- and the babysitter baked and decorated sugar cookies.
  • Social
    • A- opened the cutlery drawer a few times, exclaiming variants of “Very cool!” I’m not entirely sure if she was buttering me up to get popcorn or imitating my satisfaction with the organizer I made.
    • We visited Joy and J-. We read books and made playdough. It was good to catch up. We swapped A-‘s wooden puzzles for a playdough extruder.
    • At the parenting workshop, we learned more about positive parenting and behaviour. A- played with the childminders for most of the session.
    • A- and E- played with a ball game, a hose, and a sprinkler.
  • Pretend
    • I made dust masks for A- and me so that we could pretend to be dentists.
    • A- said to W-, “Let’s play Dead Bird!” W- said, “Dear kindergarten teacher: it’s not what you think.” We had cleaned up a dead baby bird this week, so she wanted to pretend to pick up more birds.
  • World
    • A- enjoyed chasing rainbows made by a prism.
  • Oops
    • We forgot to round up all of our garbage. Oops!

Blog posts


Category The other week % Last week % Diff % h/wk Diff h/wk
Business 5.4 10.3 4.9 17.3 8.2
Discretionary – Productive 2.2 4.9 2.8 8.3 4.7
Discretionary – Play 1.7 4.2 2.5 7.0 4.1
Unpaid work 2.3 4.4 2.1 7.4 3.5
Personal 2.3 3.0 0.7 5.1 1.2
Sleep 31.0 31.1 0.1 52.2 0.2
Discretionary – Social 0.0 0.0 0.0 0.0 0.0
Discretionary – Family 5.1 2.3 -2.9 3.8 -4.8
A- 50.0 39.8 -10.1 66.9 -17.0

So much consulting this week! There was an interesting time-sensitive challenge at work, so I jumped on it.

Weekly review: Week ending June 28, 2019

  • Kaizen
    • I updated my duplicate checker to look at package names and allow me to see the next matches.
    • I wrote a batch script to rsync photos, and I freed up space.
    • I cut and glued a wooden organizer for the cutlery drawer.
  • Us
    • I applied another polyurethane layer on the kitchen shelf and on the drawer pieces.
    • I asked for cardboard boxes from the grocery store and cardboard tubes from the kids’ clothing store. That will be handy for crafting.
    • I dropped by Melissa’s place to water her plants.
    • Italian dressing: Went well with pasta salad.
    • I tried alternating 15-minute timers so that I could focus on her and also cook dinner. It was nice deliberately making time to focus on her, although she wasn’t keen on letting me focus on cooking.
    • I sorted and scanned receipts for our tax review.
    • CRA wants to review our tax return, so I made a cover letter in Org Mode with a table of the receipt information from my Google Docs spreadsheet. I cross-referenced them with the scanned receipts. Then I used pdfjam to make a new PDF with the cover letter and the cross-referenced receipts in chronological order, updated all the page references in my summary table, and recompiled the PDF. Yay!
    • We learned a little more about temperaments in the parenting workshop.
    • I updated my ledger.
  • Fine motor
    • A- wanted me to play the hot potato game the babysitter taught her. She was also interested in practising with scissors. We made hanging shapes and the Japanese lantern from Childcraft.
  • Language
    • A- followed along with the sandpaper letter activity, including the parts where I knocked on the letters and when I asked her to take the letters to different places. She was more interested in drawing squiggles on the salt tray than in reproducing the letters, though. I might treat the salt tray as more of a sensory activity until she’s more interested in writing.
    • “Daddy, I have a favor to ask. I want to make things.”
    • A- read the numbers on the scale: 11.
    • A- put a bag of cashews in the freezer to see what would happen. When she felt it had gotten cold enough, she opened the freezer by herself. W- asked her what she thought they would be like. She said, “Look, I’m going to test it.”
    • I asked A- if I could finish her food. She said, “But it has my germs!”
  • Music
    • I took A- to the open house for the Royal Conservatory of Music. We made it only to the demo class that I’d signed up for, but that was okay. On the way home, we talked about getting another ukulele. I think it might be fun to try a good make-your-own-ukulele kit, perhaps after the porch. I want something that sounds decent and is enjoyable to play. I could get an inexpensive ukulele that’s already made, but assembling it might give us more insights.
  • Art
    • A- got the Childcraft volume on Make and Do, and she turned the pages to the paper towel dipping activity. She got the hang of turning the paper towel to dip different corners.
  • Self-care and independence
    • A- got an insect bite on her forehead.
    • I took A- to the doctor because her forehead and eye were swelling up. The doctor said that A- picked up a secondary infection after scratching her bug bite.
    • A- started taking antibiotics and antihistamines for her secondary infection. She doesn’t seem to get unusually sleepy with Benadryl, and she even woke up in the middle of the night to share some of the things she learned about antihistamines.
    • A- asked me to scrape her teeth with the flosser. I usually just do the teeth I can easily reach, but this time, I pulled her lip back and scraped her back teeth too. Yikes! Tooth decay!
    • I took A- to the dentist. She has tooth decay. It’s not yet a cavity, so we’re going to start taking her in for tooth cleaning and fluoride varnishes, being stricter about not snacking throughout the day, and brushing more often. If she can tolerate being at the dentist and we can stop it from getting worse, we might be able to fix it at the dentist with some nitrous oxide. If not, she may have to go under general anesthesia again, which would be tough on her body.
    • I made a concerted effort to brush her teeth after every meal today, offering videos of herself as a distraction.
    • A- sharpened pencils all by herself.
  • Eating
    • We made vanilla ice cream using the bag-in-a-bag approach. The first ice bag tore, so I added another bag and wrapped a cloth bag around it too. A- approved of the ice cream and asked for lots of it. That was fun.
    • A- really wanted cartilage. She gnawed the ends off all the chicken wings from the sotanghon I packed for lunch.
  • Emotion
    • A- was grumpy. I asked her what could help her calm down. She said, “I want to dance.” She used the demo mode on the piano to select a piece, and we danced for a bit.
  • Household
    • A- wanted to help wax the new kitchen shelf. She and W- took turns applying wax and wiping it away. Wax on, wax off.
    • A- used a driver to screw in Phillips and Robertson screws. She liked how much faster it was with the power tool. She also had fun swapping the bits for the stubby screwdriver.
  • Social
    • “Don’t forget to say thank you.”
  • Pretend
    • A- figured out that the syringe plunger was just the right size to look like a seal for the squeeze bottle, so she liked pretending to make something new.
    • We had fun pretending she was a firefighter and I was a fire.
    • A- put a cloth book on her head and balanced other books on her hands. Then she waved her hands around, reenacting pandanggo sa ilaw.
    • Out of the blue, A- said, “Stanchion!” After I looked it up, I remembered it from the book on milking cows. A- asked me to pretend to be a stanchion, so we had a bit of fun with that.
  • Cognition
    • A- pretended to apply temporary tattoos, counting all the way to thirty with just a few hints.
  • World
    • We started making a bucket conveyor using the anti-slip mat and the egg carton.
    • We made a water dispenser from a bottle, some tubing, and cardboard. I didn’t need to worry about whether things were food-safe, as A- happily dispensed and refilled the water without drinking any.
    • I finished the bucket conveyor. The conveyor belt slips sideways, but it’s a good start. A- had fun conveying ping pong balls and cat toys into an empty yogurt container. I replaced the yogurt container with a ball return mechanism made out of a guacamole container and a cardboard ramp formed into a V with rubber bands. Yay!
    • We used a triangular prism to explore rainbows.

Blog posts


Category The other week % Last week % Diff % h/wk Diff h/wk
Business 0.4 5.4 5.0 9.1 8.4
Discretionary – Productive 1.1 2.2 1.1 3.6 1.8
Sleep 30.0 31.0 1.0 52.0 1.7
Personal 2.2 2.3 0.1 3.9 0.1
Discretionary – Social 0.0 0.0 0.0 0.0 0.0
Discretionary – Play 1.8 1.7 -0.0 2.9 -0.1
A- 50.2 50.0 -0.2 84.0 -0.3
Unpaid work 5.6 2.3 -3.3 3.9 -5.5
Discretionary – Family 8.7 5.1 -3.6 8.6 -6.1

Weekly review: Week ending June 21, 2019

  • Kaizen
    • W- replaced the kitchen drawers. I helped take out the old rails and use the chop saw.
    • Baked rainbow trout: Yummy and easy.
    • I managed to put my bike on the hook again, yay me!
    • W- taught me how to use the table saw.
    • We cleaned the sauce cabinet in preparation for painting it, and W- trimmed it to fix the gaps.
    • W- and I built a kitchen shelf out of Baltic birch, and I applied a polyurethane coat to it.
  • Us
    • I booked our flights and bought travel insurance.
    • I booked hotels for our stopovers. I decided to stick with the hotel we tried last time. We’ll check out the train in case we need to take it to get to the airport early.
    • I biked to the pool with A- in the trailer. I managed to make it over the bridge on Dundas West, yay!
  • Fine motor
    • A- wanted to try sungka with four shells in each pot. She sometimes needed to use two hands, but she patiently did it even when her turns were pretty long.
  • Sensory
    • A- and I made sand angels.
    • A- enjoyed swimming with some floaters on. She imitated the other kids in practising how to get into the pool with my help. She also experimented with lying backwards while I supported her.
  • Language
    • “Who is my baby?” “Me.” “Who is my wonderful baby?” “Me.” “Who is going to bed soon?” “You.”
    • W- and I were talking about travel plans and whether I might want to spend extra to reduce hassle. He said, “X dollars? That’s not a lot.” A- chimed in with, “That’s a lot.”
    • “I’m not paying attention.”
    • “Wow, very cold.” – A- after splashing herself with a small amount of water which turned out to be cold.
    • I made small sandpaper letters: c, a, t, m.
    • “Whoa, such a cool thing.” – A- swinging around suddenly on some playground equipment
    • A- asked W- if she could climb the ladder, but W- couldn’t figure out which ladder she meant. Some time later, A- saw the platform. She gestured to it and said, “That’s the ladder I was talking about.” It’s nice to see that she can remember and politely clarify.
  • Music
    • I signed A- up for the Smart Start music classes at the Royal Conservatory of Music – the regular one, not the one with Suzuki piano. It’ll be her third year doing it, and I’m looking forward to learning more songs and games with her while I’m allowed to attend. It’ll probably be a good intro to independent classes, too.
  • Self-care and independence
    • Another kid accidentally threw sand in A-‘s face. A- cried the sand out of her eyes.
    • A- wanted to stay home instead of going to nature class or school, so we played at home most of the day.
  • Eating
    • We brought popcorn to the potluck. A- liked lumpia and watermelon.
    • I made heart-shaped pancakes. A- liked them.
    • A- liked the crusty part of the samosas.
  • Emotion
    • A- had a tantrum in the morning about not being allowed to help clean up cat poo. When she calmed down, I talked to her about how our brains flip out. At bedtime, she asked me why her brain had flipped out earlier, and we talked a bit more about emotional regulation.
    • At bedtime, A- asked me why she grabbed the kitchen towel from W- a few days ago. We talked about why she locked on to that and why W- decided to find something else to do.
  • Household
    • A- wanted to make her bed before getting into it.
    • A- started cutting up one of her old dresses to make a sleep sack for her doll, so I helped her make it.
    • A- was curious about caulking. W- let her squeeze some caulk onto paper.
  • Social
    • A- helped pack up at school. She put toys into bags.
    • A- wanted a twig that H- had. They had previously fought over other twigs, which resulted in us talking to the kids about grabbing and stuff. A- looked around and spotted some chalk. She successfully traded a piece of chalk for the twig she wanted.
    • A- approved of slurping noodles and disapproved of slurping applesauce.
    • A- didn’t want to go to the parenting workshop today. She wanted to stay home and make a sleep sack. I said we already had one, and she said she wanted to make her own. She negotiated, outlining her proposal with her fingers: “First, sew. Second, play. Then workshop. Those are choices.” We discussed material choices a bit before settling on salvaging the zipper from one of her sleepers. I broke my serger needles because I was rushing and a bit frustrated, so I put it aside and A- agreed to go to the workshop with me. She had a long nap in the stroller. After we came home, I replaced the needles and played with A- some more.
  • Pretend
    • A- pretended to be a pancake cooking on all sides at bedtime.
  • Cognition
    • A- did a good job paying for llama food and a temporary tattoo with the $3 I gave her. She felt brave when she fed the llamas, and she helped count up to thirty while waiting for the tattoo to transfer. She was curious about the chickens, but she was a little scared of them too.
    • A- did a good job solving the alphabet puzzle. She easily identified letters and matched them up with the slots with only occasional hints, and she took turns with another kid.
  • World
    • I made a cardboard conveyer and we mechanized it with a motor from the Technic set. That was fun!
  • Other
    • A- enjoyed picnicking with the babysitter. She also had fun climbing onto the platform we were using to work in the kitchen.

Blog posts


Category The other week % Last week % Diff % h/wk Diff h/wk
A- 39.0 50.2 11.2 84.3 18.8
Discretionary – Family 4.5 8.7 4.3 14.7 7.1
Discretionary – Social 0.0 0.0 0.0 0.0 0.0
Sleep 30.3 30.0 -0.3 50.4 -0.5
Unpaid work 6.0 5.6 -0.4 9.4 -0.7
Discretionary – Play 3.8 1.8 -2.0 3.0 -3.4
Business 3.4 0.4 -3.0 0.7 -5.1
Personal 5.7 2.2 -3.4 3.8 -5.7
Discretionary – Productive 7.3 1.1 -6.2 1.8 -10.5