Posts

Showing posts from 2022

SVG rendering of HTML in GNU Emacs

Image
For viewer-only application or for printing purposes, an HTML document can be converted into SVG in GNU Emacs. Thus you can take advantage of tabular layout and CSS.   Note: It's better to run browser as a separate process since it involves running Javascript in a sandbox environment. Rendering is the easy part - security is what makes a browser complicated.   Code: https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el (load "~/svg.el")   ;; Execute following command in HTML buffer M-x svg-render-html 

ELLE Looks Like Emacs

Image
  If you like revisiting history, here's how you can run Elle on Minix. Download the minix image from https://github.com/davidgiven/minix2 . You can run the image in KVM. Login as root and run " elle file.txt ". # Install KVM and download image   sudo apt install qemu-kvm curl https://github.com/davidgiven/minix2/files/917987/minix-2.0-hd-64MB.img.gz -o minix-2.0-hd-64MB.img.gz gzip -d minix-2.0-hd-64MB.img.gz # Run the image in KVM kvm -hda minix-2.0-hd-64MB.img     Update software Compile the libraries, commands and kernel         a. # cd /usr/src         b. # make world   We need to update the bootloader as well.         a. # cd /         b. # mv boot boot.old         c. # cp /usr/mdec/boot .         d. # installboot -d /dev/c0d0p0s0 /usr/mdec/bootblock boot Now reboot.         a. # shutdown     References ELLE command reference Minix upgrade instructions    

Take Charge of PDF in GNU Emacs

Image
Display popup annotation in docview   All or None Docview is the default major-mode for displaying PDF in Emacs. It converts each page into an image using ghostscript into a temporary folder (/tmp/docview<nnnn>) and displays the same. For large PDF document, this conversion is unnecessary in most cases - especially when one is looking at the document for quick reference.   An ideal solution would be to convert pages on demand. However, for this, one would need to know the number of pages in the document. This can be done either by some external tools like pdfinfo or one would need to parse the metadata in the document. So here's some elisp code for the same.   (require 'pdf) (pdf-get "Root.Pages.Count")   or   M-x pdf-total-pages   ;; Metadata about the document (pdf-get "Root.Metadata")     So here we are - now that one can parse the metadata, what else can we do? Form fields and Embedded scripts M-x pdf-form PDF supports embedded Javascript for add

AWS API Usage in Elisp

Image
Here's some sample elisp code for signing Amazon Web Services (AWS) API requests . The value (first element) returned by (aws-sign4) is used in Authorization header while making a request. When the function is called with an expires value, it returns a URL which can be directly used in a browser. (require 'aws-sign4)   (let ((*aws-credentials*        (lambda ()          (values "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))))   (aws-sign4 :region "eu-west-1"              :service "s3"              :host "s3-eu-west-1.amazonaws.com"              :path "/some-bucket/some-file"              ))   (let ((*aws-credentials*        (lambda ()          (values "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))))   (aws-sign4 :region "us-east-1"              :service "iam"              :host "iam.amazonaws.com"              :params '((&qu

One-click Social Media Client

Image
Reddit: Dashboard and details view Twitter: Dashboard and details view Tumblr: Dashboard and details view Youtube: Dashboard and details view   GNU Emacs as a Social Media Client Consumption of social media typically necessitates few repeated actions - like, share, comment and follow. If these actions are assigned to convenient keyboard keys, the consumption becomes easier - no more pointing and clicking tiny icons. Here's an attempt to unify this experience using GNU Emacs, tumblesocks and oauth2.   (require 'tumblesocks) (require 'oauth2)   ;; service below is one of twitter, reddit or tumblr (setq tumblesocks-service-conf    (service . ( client-id secret-key redirect-url ))     Use M-x sm-twitter , M-x sm-reddit , M-x sm-youtube or M-x sm-tumblr . First time, it will open a browser window. You'll need to login to the service and allow the permissions in following window. Then you'll be redirected to a URL. You'll need to copy the code (code= value#_ ) in th

Oauth2 sample flow in Elisp

Image
Here's a modified version of oauth2.el . This Elisp code works for oauth2 flow using Twitter, Gmail, Reddit and Tumblr. To add more services, add the provider URLs to the variable oauth2-service-conf. To make API calls, set the service configuration values (client-id, secret-key and  redirect-url) in the variable t-service-conf. Then use the examples in the usage section. (require 'oauth2)  (setq t-token nil) (setq t-service-conf   '((service . ( client-id secret-key redirect-url ))))   (defun t-api-oauth2-request (url params method service auth-scope                        &optional headers)   (let* ((oauth2-conf (assoc service oauth2-service-conf))      (conf (assoc service t-service-conf))      (t-consumer-key (nth 1 conf))      (t-secret-key (nth 2 conf))      (t-callback-url (nth 3 conf))      (data nil))     (unless (assoc service t-token)       (push (cons service           ( oauth2-auth (nth 1 oauth2-conf)                    (nth 2 oauth2-conf)               

Tumblr access from GNU Emacs

Image
Dashboard view (left) and detail view (right) tumblesocks-mode allows you to access Tumblr from GNU Emacs. Best part is - it has pagewise navigation by default instead of endless scroll. Use c for new post, f for follow, l for like and r for reblog. Since the repository is dormant and I needed some customization, I created a fork . It includes some UI changes, fix for emoji display, shorter tumblesocks alias and fix for displaying post at point, like post, reblog post, goto page etc.  

Compose Emoji in GNU Emacs

Image
  Modern emojis are composable - you can compose multiple emojis into a new one. Most commonly, this is done using Zero-Width Joiner or ZWJ character (#200D). Though not all combinations are valid. The valid combinations are defined by the font. e.g. you can combine as follows: Person + rocket = Astronaut Person + manual wheelchair = Person on wheelchair Following function will help you insert ZWJ in between selected text. (defun emoji-compose ()   "Compose emoji from components."   (interactive)   (unless (region-active-p)     (error "Select a sequence of emoji components"))   (let* ((start (1+ (region-beginning)))      (len (- (region-end) start)))     (goto-char start)     (dotimes (i len)       (insert #x200D)       (forward-char)))) For auto-completion, you can use company-emoji . References Unicode defined ZWJ sequences Unicode ZWJ specification  

Comics Builder in GNU Emacs

Image
  Generate comics strip from a script in GNU Emacs. First, create a folder containing artwork. You can use samples from [2]. It should have three subfolders - faces, poses and backgrounds. Images can be GIF, JPG or PNG. Filenames for face and poses follow a convention: <id>-<emotion>.<ext> . Please ensure you have atleast one file for neutral emotion . Set appropriate values for following variables: comics-artwork - Folder containing artwork comics-col-max - Maximum no. of columns (default: 2) comics-emotions - Alist of emotions and words used to describe them comics-avatars - A list of cons cells (FACE-ID . BODY-ID) Open a file containing the script (sample below) and run M-x comics. This will generate an SVG image for the comics strip which will fit the display window. Panels are rendered with fixed font-size so that it is always readable. Actors are assigned an avatar from comics-avatars sequentially as they appear in the script. Normally, all the actors are drawn

Twitter access from GNU Emacs

Image
  twittering-mode allows you to access Twitter from GNU Emacs. If you have curl installed on your system, it mostly works out of the box except for images. Use u for new tweet, RET for reply, and C-c C-m or C-c RET for retweet. For images, you need to follow these instructions . It basically defines a new format string %I for images in (twittering-generate-format-table).  ("I" .        (let* ((entities (cdr (assq 'entity ,status-sym)))               text)          (mapc (lambda (url-info)                  (setq text (or (cdr (assq 'media-url url-info)) "")))                (cdr (assq 'media entities)))          (if (string-equal "" text)              text            (let ((twittering-convert-fix-size 360))              (twittering-make-icon-string nil nil text)))))   You can also change the display format string to suit your needs. Typically, you'd change the faces and the placement of fill string.  (setq twittering-use-native-retweet t tw

GNU Emacs for Kids: Matching game

Image
  Build learning exercises for kids using GNU Emacs. The game basically builds up a grid of file names (without the extension) and images. So you can create separate folders for different activities e.g. for colors, shapes, body parts, relationships etc. It randomizes the sequence each time which encourages the kid to learn the relationship instead of the pattern. - M-x game-match If you're running for the first time, it will ask you for a directory of images. You can re-run the same exercise till the kid gets it right. To change the activity, run the command with a prefix. - Use click and drag to draw joining lines. - Use u for undo and q or RET for quit. Code https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/play/game-match.el    

Interactive XPath and JSON Path Builder in GNU Emacs

Image
  Build XPath and JSON path interactively in GNU Emacs. XPath parsing uses xmllint (part of libxml2-utils package in Debian). For JSON, no external tool is used. The code exposes two APIs: - M-x xpath-builder and M-x json-path-builder for interactive usage - (xpath-resolve xpath) and (json-resolve json-path) for programmatic usage Code https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/xml/xpath.el   Screenshots Xpath JSON Path

Swipe for Text Input in GNU Emacs

Image
  Swipe on an on-screen keyboard for text input in GNU Emacs.  (require 'sweep)   ;; Ensure variable points to the location of keyboard.svg file  (setq sweep--keyboard (concat data-directory "/images/keyboard.svg"))   - Execute M-x sweep-mode .   Code: https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/sweep.el https://gitlab.com/atamariya/emacs/-/blob/dev/etc/images/keyboard.svg  

Chronicles of Emacs : The Editor and the T-shirt

Image
T-shirt pattern   You can generate a preliminary pattern based on your measurements for a custom fit T-shirt using GNU Emacs. This will generate an SVG image which you can print and use for tailoring. Don't forget to add allowance for seams. - Set your measurements in tailor.el   (defun tailor--bust (svg)   (let* ((cmds nil)          (body-length    72)          (chest          56)          (waist          56)          (shoulder       48)          (sleeve-length  21)          (arm-hole       26.5)          (neck-back      5)          (neck-front     10)          (neck-opening   17)          (sleeve-opening 19) - Evaluate buffer using menu or M-x eval-buffer . - Execute M-x tailor to generate the SVG.   Code: https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/tailor.el    

Screen mirroring using GNU Emacs

Image
Screen mirroring using GNU Emacs from Debian XFCE to LG UJ632T   Note: Don't forget to quit properly (or use wpa_cli p2p_cancel ). Else your computer will continue to scan for peers in the background. Config (require 'tv) (setq wfd-wpa-cli " /usr/sbin/wpa_cli ")   Code https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/tv.el https://gitlab.com/atamariya/hostap/-/blob/tools/wpaspy/wfd.py (RTSP server)   Setup We need to be able to run wpa_cli and nmcli as a normal user. Hence we will add the user and the tools to netdev group.   - Edit /usr/lib/systemd/system/wpa_supplicant.service (as root) ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant -G netdev   - Restart wpa_supplicant (as root). systemctl daemon-reload service wpa_supplicant restart    - Modify user group, file permissions and path. sudo adduser <username> netdev chown -R :netdev /usr/sbin/wpa_cli /var/run/wpa_supplicant/* export PATH=/usr/sbin:$PATH    - Start the RTSP server. python3 wfd

Mission control in GNU Emacs

Image
  Mission control or desktop/window overview in GNU Emacs. This is an Emacs buffer showing some images in a fullscreen frame. The first line shows images of workspaces. The rest are images of active windows in current workspace. It uses the following external tools: wmctrl - For switching applications and workspaces xdotool - For getting id of active window xwd - For taking screenshots in XWD format ffmpeg - For scaling and converting XWD to PNG format Install these essential tools in your system.  $ sudo apt install wmctrl xdotool xwd ffmpeg Load library task.el  (require 'task) Run M-x task-view or M-x task-view-fullscreen . Use mouse to select, g to group, G to ungroup, m to start a move operation and ESC to cancel. Use double click to activate a window or desktop. Press q or RET to exit. Pro Tip: You can select multiple windows.   Code: https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/task.el   Note: xfda

GNU Emacs as a Desktop widget

Image
    GNU Emacs has a lot of in-built features which can enhance your computing experience while acting as a desktop widget .e.g. calendar, scratch pad, clock (external) etc. Even when you are not using it as the main application, it can prove useful as a companion application. In the image, menu bar, tool bar and scroll bars have been turned off. You might want to make it sticky (appears in all desktops) and maximized vertically using following command (you can get <win-id> using xwininfo command): $ wmctrl -b add,sticky,maximized_vert -r <win-id> -i  

GNU Emacs Gestures

Image
 Use multi-touch gestures in GNU Emacs.   - Install touchegg https://github.com/JoseExposito/touchegg - Create a copy of touchegg.conf $ mkdir -p ~/.config/touchegg && cp -n /usr/share/touchegg/touchegg.conf ~/.config/touchegg/touchegg.conf   - Add a section for Emacs (pinch to zoom) before closing <touchegg> tag.    <application name="Emacs">     <gesture type="PINCH" fingers="2" direction="IN">       <action type="SEND_KEYS">         <repeat>true</repeat>         <modifiers>Control_L</modifiers>         <keys>x+KP_Subtract</keys>         <decreaseKeys>KP_Add</decreaseKeys>       </action>     </gesture>     <gesture type="PINCH" fingers="2" direction="OUT">       <action type="SEND_KEYS">         <repeat>true</repeat>         <modifiers>Control_L</modifiers>         <

Rabbit hole: Windows + Linux + Emacs + Vim

Image
A computing Rabbit hole!!! Windows 10 running WSL2 (debian) and VcXsrv X server GNU Emacs compiled under WSL2 with XWidget support GNU Emacs running embedded Vim using XWidget's XEMBED protocol

Screen Mirroring in GNU Linux

Image
Screen mirroring allows you to display your laptop screen on a TV via Wifi Direct . This is also known as screen casting, Miracast, Wifi Display or Wifi P2P. Usage of Wifi Direct means you don't necessarily need a router or a working network. The data is streamed using RTSP . However, it doesn't use the standard RTSP port. The port information is shared during connection process (usually defaults to 7236 as per Miracast specifications). Also, the RTSP server must support additional Miracast related negotiations. Note: Feature-wise, Second Screen or DIAL (DIscovery And Launch) provides similar experience (primarily for Youtube and Netflix apps). But this (DIAL) requires both the devices to be in the same network. Debian XFCE meets LG 4K TV (UJ632T) The core of this technology in Linux is wpa_supplicant (or its variant - connmand or miracle-wifid). connmand (for WDS ) and miracle-wifid (for MiracleCast ) also manage your network interface. You might also have NetworkManager