Posts

Showing posts with the label emacs

Plan 9 Remote File Access from Emacs

Image
  Plan 9 Operating System uses 9p protocol for file access. This is an Elisp implementation of the protocol. Plan 9 ( 9front distribution) is running in QEMU with NAT networking. Local port 12564 is forwarded to 9fs service port 564 in the virtual machine.   Code https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/net/plan9.el   Troubleshooting Plan 9 connection Ensure you are booting with  -a tcp!*!564  parameters. (Tip: You can add these to your /n/9fat/plan9.ini) Ensure you have configured the network interface   ip/ipconfig   Ensure you have an IP address  cat /net/ndb  Ensure you are running cpu+auth server  cpurc  (Optional) Start graphics mode  screenrc   (Optional) Start window manager  rio   (Optional) List open connections  netstat    (Optional) Monitor network traffic  snoopy   (Optional) Debug authentication  auth/debug  (Optional)...

Emacs: Binary File Viewer

Image
  Quick visualization tool for Binary data using C header definition. Semantic parses the C header file and generates a type definition. The type definition is passed to bindat-unpack along with the binary data. The result is displayed using speedbar . ;; Note: The command works on the binary data in the current buffer.   M-x hexl-form   (hexl-form)      The image shows the example included in the commentary section of bindat.el .   Conversions (format "%02X" 255) ;; => "FF" (string-to-number "FF" 16) ;; => 255   ;; Little endian unpacking (let* ((bindat-raw [1 2 3 4 5 6 7 8])           (bindat-idx 0))   (bindat--unpack-u64r))   ;; Little endian packing (let* ((bindat-raw [0 0 0 0 0 0 0 0])           (bindat-idx 0))   (bindat--pack-u64r #x0102030405060708)   bindat-raw)      Insert Binary Data Emacs creates a multibyte buffer ...

CEDET: Across the Language Barrier

Image
Emacs at its core is a Lisp interpreter written in C. If you are an Emacs developer, this means you often need to jump between C and Lisp programming languages. CEDET is capable of maintaining project-wide tag database and hence allows the user to seamlessly jump across the definitions in either C or Lisp.    Demo: Jump to definition across Lisp and C (including pre-processor) using CEDET . Note: Emacs provides necessary tools to make development easier.  find-function will also do the job. However, this article is about CEDET. Another useful application is when you are editing an HTML which usually entails editing HTML, CSS and JS. Setup instructions are here: https://lifeofpenguin.blogspot.com/2021/04/gnu-emacs-as-lightweight-ide.html

Emacs Font is wider

Emacs Font is wider than other applications. Most people don't notice the difference. If you can perceive it, you are not hallucinating. This can be attributed to the following: Points per inch #ifndef HAVE_ANDROID /* Number of pt per inch (from the TeXbook).  */ #define PT_PER_INCH 72.27 #else /* Android uses this value instead to compensate for different device    dimensions.  */ #define PT_PER_INCH 160.00 #endif    Emacs definition is larger than the standard definition . The DTP point is defined as 1⁄72 of an inch.  Round-off error Emacs definition : /* Return a pixel size (integer) corresponding to POINT size (double)    on resolution DPI.  */ #define POINT_TO_PIXEL(POINT, DPI) ((POINT) * (DPI) / PT_PER_INCH + 0.5) /* Return a point size corresponding to POINT size (integer)    on resolution DPI.  Note that though point size is a double, we expect    it to be rounded to an int, so we add 0.5 here.  If ...

Emacs: A non-intrusive browser

Image
  Web is simple. Browser can be simpler.     Features No pop-up ads Content first (CSS and images are loaded asynchronously) No beacon or marketing pixel ( zero pixel) image tracking Split panes Fully customizable (custom theme using CSS) Fully extensible (write your plugins/extensions) Easy cookie mangement   The technical details are here .  

HTML Renderer (Emacs)

Image
  Emacs: A non-intrusive browser An Elisp implementation of HTML rendering using SVG. The browser functionality is an extension of eww . For Javascript, you can use either NodeJS or QuickJS as a JS interpreter . Developer Note: The entry point is shr-render.   Table Colspan example Rowspan example Sample Table <html>   <body>     <table border="1">       <tr bgcolor="#9acd32">         <th style="text-align:left">Title</th>         <th style="text-align:left">Artist</th>       </tr>       <tr>         <td>Empire Burlesque</td>         <td>Bob Dylan</td>       </tr>     </table>   </body> </html...

The Oval Editor (Emacs)

Image
   The Oval Editor is a feature which allows the user to combine text with advanced formatting and drawings seamlessly in Emacs. This is an amalgamation of several disparate features developed over a period of time . It is also available as a single package in my Emacs fork . Draw and Scribble Notes in GNU Emacs   Text inside a shape (uses librsvg fork ) Context menu   Variable fonts Faux Bold and Italics   Annotate Completion Candidates   Text wrap at fixed pixel width in edit mode (only available in my Emacs fork) Symbol selector     (require 'formula)    Use M-x formula-draw to start drawing in a buffer. Select rectangle shape by pressing r. You can use the grid lines to align the shapes. You may exit the drawing mode by pressing q. Double-click on the shape to start editing the text inside a shape. The editing area is restricted to the width of the enclosing shape. Use right-click context menu to apply formatting. The demo use...

GNU Emacs as a Comic Book Reader

Image
  Comics are available in digital format as a collection of images in a compressed ZIP or RAR file (.cbz or .cbr file extension respectively). These can be enjoyed in GNU Emacs with full access to image viewing capabilities using keybindings.   # Make sure you have unrar installed for CBR files # apt install unrar   (require 'arc2-mode)   (setq archive-summarize-files-fn 'archive-summarize-files-as-thumb)     Note: The archive-mode is capable of displaying the list of files in an archive; though it depends on external tools for extraction. For JPG and PNG, Emacs can resize the image without external convertor (ie. imagemagick). However, some menu options for image transformations in image-mode might not be available. Use the following patch for image-mode.el . @@ -460,16 +460,16 @@ image-mode-map       :help "Show image as hex"]      "--"      ["Fit to Window Height" image-transform-fit-to-...

GNU Emacs as a Shopping App

Image
  How do you find the best price for items while shopping online? You can go to each website and compare yourself manually. Or let Emacs do the hard work for you!! You can start with a shopping list in a normal buffer. shop-mode minor mode allows you to search, compare and add products to your cart across multiple providers (presently Bigbasket and Jiomart ). You can finish the payment on the provider's website. Note: You can use (url-cookie-store) for managing cookies programmatically or url-cookie-list interactively. Keybindings s     Search the item o     Order the results by price, unit price, brand etc. q     Quit Unit price comparison allows better deals   Config (require 'shop)   ;; For webp image support (setq image-converter 'imagemagick)  ;; An example. Add appropriate cookies changing name, value and domain. (url-cookie-store "_bb_vid" "NTY2NzQ4MDAwNw==" "-1" "www.bigbasket.com" "/" t)   Code https://g...

Stream ListenBrainz.org Music Playlist in GNU Emacs

Image
    Here's an Emacs Multimedia System (EMMS) extension for streaming ListenBrainz.org music playlist using mpv player (with ytdl support). Irrespective of how satisfied you are with your music streaming service, you should plan for maintaining a playlist of your favorite music in an open format. The popular service might be forced to close down because of non-profitability even when you are willing to pay for ad-free music streaming. e.g. Worldspace radio customers even paid for the device in addition to the subscription fees. The code uses following function from tumblesocks codebase. In case you don't use tumblesocks, you'll need to define it yourself. (defun tumblesocks-api-process-response (&optional service)   "Process Tumblr's response in the current buffer, returning JSON or signaling an error for other requests."   (decode-coding-region (point-min) (point-max) 'utf-8-dos)   ;; the following copied from url.el   (goto-char (point-min))  ...

Zen Emacs: First Look

Image
  Zen is a minimal Emacs ( pl. Emacsen ) with multi-thread support . It is a fork of Zepl . (Edit 3/9/23: Zen Emacs is a better name compared to Zep). Demo The video demonstrates: Split window Indirect/cloned buffer - same content but different points (cursor) Asynchronous shell command (top) execution and view update Parallel editing while the command runs in the other window   Components Zepl - Editor backend tinylisp - Lisp interpreter ncurses - Terminal UI Code https://gitlab.com/atamariya/tinylisp (dev branch)  

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...

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))      ...

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    ...

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

Hit-a-Hint : Didn't know I needed it!

Image
Hit-a-hint was originally developed as a plugin for Firefox. The plugin highlights the links on a webpage with an accelerator hint key. You can simply type the hint to visit the URL. How is this useful? If you notice, the hint consists of permutation of keys on the home row in the keyboard. So your link selection is typically limited to smaller number of keys which are repeated instead of all the keys if you were to select by the anchor text. This idea is implemented as a plugin for all the major browsers. For Emacs, you can use emacs-webkit . Have you tried browsing web using a keyboard? If you haven't yet, I suggest you give it a try.

gVim in GNU Emacs

Image
  You can also embed gVim in GNU Emacs (GTK build with X11 backend). There are two things to take care of in this case - moving focus to the embedded widget and redirecting keyboard input to the widget. A GTK widget can only have focus if it's set that way (remember there are multiple widgets in a window): // Allow to receive keyboard input gtk_widget_set_can_focus (widget, TRUE); // Receive keyboard input gtk_widget_grab_focus (widget);   Emacs filters keyboard events (KeyPress) before passing it to GTK. That's how C-g always works in Emacs. When Emacs receives XEMBED_REQUEST_FOCUS (event->type == ClientMessage && event->xclient.message_type == dpyinfo->Xatom_XEMBED && event->xclient.data.l[1] == XEMBED_REQUEST_FOCUS) , we need to set input focus to the widget using XSetInputFocus() using the handle event->xclient.window . Additionally, we set a flag that a widget is active. Whenever this flag is active, we stop filtering keyboard events. T...

PCB Design in GNU Emacs

Image
Gerber For fun, here's a Gerber file generated from SVG footprints drawn in GNU Emacs . Note: gerbv displays polygon pad incorrectly as circle in fast mode . You should use use normal mode for this. Or else use gerbview . 3D Model If you have properly modeled footprints (1:1 scale, XY plane of the 3D model on the PCB and origin at the center of the bounding box), then you can easily generate 3D view of the assembly. In this screenshot, you can see the generated model being rendered by view3dscene. The code expects eda:url attribute to point to the 3D model (.wrl file for VRML 2.0). The shape with eda:type="board" is used as the PCB. (require 'gerber) (setq canvas-plugin-map pcb-canvas-map) Fancy fonts on Silkscreen Do you want fancy fonts on your PCB silkscreen? You can use a Hershey font or stroke font in SVG format to achieve the desired result. A small collection of these fonts are available at https://gitlab.com/oskay/svg-fonts . Code: https://gitlab.com/at...

SPICE simulation in GNU Emacs (From schematics)

Image
Now you can design and run SPICE simulation for simple circuits in GNU Emacs. Since the circuit and graphs are in SVG format, you can easily annotate and share it on the web or embed it in a document.   Video tutorial for configuring the circuit diagram, running the simulation and plotting the results is below:  Video tutorial for drawing the circuit diagram using widgets is below:   Code:   https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/spice-mode.el   Setup: Setup is covered in following blog posts. https://lifeofpenguin.blogspot.com/2021/10/svg-widget-in-gnu-emacs.html https://lifeofpenguin.blogspot.com/2021/10/spice-simulation-in-gnu-emacs.html Additionally, we need to make special spice plugin (defined in spice-mode.el) available to canvas-mode. This makes plugin keybindings available via C-x in canvas-mode. To do this, add following to .emacs (setq canvas-plugin-map spice-canvas-map)  ...

SVG widget in GNU Emacs

Image
  (Top) SVG sprite sheet (Bottom) widgets from sprite sheet (Left) SVG widget in Emacs buffer Now you can use SVG widget in GNU Emacs. That is, use an SVG image or fragment as background for push-button widget in Emacs buffer. You can also specify the width and height of the widget for finer control. Generally speaking, you can use any type of image for this purpose. But SVG suits best because you can draw widget of any size without any distortion.   The ability to use SVG fragment means you can define multiple symbols in an SVG and use the same as a sprite sheet or a symbol library for your UI requirements. Thus the number of files to be managed is reduced. An SVG symbol library is a simple SVG file with each symbol as a direct descendant of the root node. Video above shows an example of such usage. Another use case would be better looking customize form. Or at the very least, rounded "Save" and "Cancel" buttons. In other words, a more visually appealing UI in grap...