Write Emacs packages in Swift!

Last update: Aug 9, 2022

EmacsSwiftModule

A Swift library to write Emacs plugins in Swift!

Overview

Emacs Swift module provides a convenient API for writing dynamic modules for Emacs in Swift. It marries a dynamic nature of Emacs Lisp with strong static typization of Swift and hides the roughness of the original C API together with harder aspects of that language such as a lack closures and manual memory management. It also translates Emacs Lisp errors and Swift exceptions into each other.

A Quick Tour

EmacsSwiftModule allows you to call functions from Emacs Lisp using Swift's own types.

let two: Int = try env.funcall("+", with: 1, 1)
assert(two == 2)
try env.funcall("message", with: "%S %S", "Hello", 42)

And define your own Lisp functions out of Swift closures

try env.defun("foo") {
  (x: Int, y: Int) in x + y
}
try env.defun("bar") {
  (input: [String]) in input.joined(separator: ", ")
}

that can be easily used in Emacs Lisp

(foo 1 1) ;; => 2
(bar ["Hello" "World"]) ;; => "Hello, World"

It handles errors on both sides so the user can almost always simply ignore them.

try env.defun("always-throws") { (x: Int) throws in
  throw MyError(x: x)
}
try env.defun("calls-afdsiufs") {
  (env: Environment) in
  do {
    try env.funcall("afdsiufs", with: 42)
  } catch EmacsError.signal {
    print("Whoops! It looks like 'afdsiufs' doesn't exist!")
  }
}

And on the Lisp side too

(always-throws 42) ;; => raises (swift-error "Swift exception: MyError(x: 42)")
(calls-afdsiufs) ;; => nil because we caught the error

The same happens when a type requirement expected in Swift is not met.

(foo "Hello" "World") ;; => raises (wrong-type-argument numberp "Hello")

GitHub

https://github.com/SavchenkoValeriy/emacs-swift-module
You might also like...

Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Jan 24, 2022

Swift-compute-runtime - Swift runtime for Fastly [email protected]

swift-compute-runtime Swift runtime for Fastly [email protected] Getting Started Crea

Jul 30, 2022

Swift-HorizontalPickerView - Customizable horizontal picker view component written in Swift for UIKit/iOS

Horizontal Picker View Customizable horizontal picker view component written in

Aug 1, 2022

swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

Jul 17, 2022

Sovran-Swift: Small, efficient, easy. State Management for Swift

Sovran-Swift: Small, efficient, easy. State Management for Swift

May 17, 2022

Approximate is a Swift package that provides implementations of floating point comparisons for the Swift ecosystem

Approximate Approximate floating point equality comparisons for the Swift Programming Language. Introduction Approximate is a Swift package that provi

Jun 1, 2022

A Swift app, named 'iPose', for iPhone's pose measurement based on Swift.

iPhone's pose measurement based on Swift. This is a Swift app, named 'iPose', for iPhone's pose measurement based on Swift. This is a side project to

Jul 26, 2022

Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Jul 20, 2022

Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

 Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Aug 10, 2022
This repo shows how to setup and use GitHub Actions as a CI for Swift Packages
This repo shows how to setup and use GitHub Actions as a CI for Swift Packages

GACalc This repo shows how to setup and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib List of the all available envi

Nov 3, 2021
A software bill of materials (SBoM) generator for Swift packages

Swift Package SBoM A software bill of materials (SBoM) generator for Swift packages. Run this command to print a JSON representation of a CycloneDX SB

Jun 22, 2022
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Jun 16, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

May 20, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Aug 7, 2022
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

Jul 24, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Jul 16, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

Apr 6, 2022