Skip to content

Instantly share code, notes, and snippets.

@danielmartin
danielmartin / kill-diff.el
Last active March 10, 2021 09:16
Emacs function to kill added/removed lines of diff output, removing the diff markers
(defun dm/kill-diff (arg)
"Kill added/removed lines of diff output, removing the diff markers.
Without a prefix argument or a positive argument, kill the added
lines. With a negative argument, kill the removed lines."
(interactive "P")
(kill-new
(thread-last (buffer-substring-no-properties
(region-beginning)
(region-end))
(replace-regexp-in-string
@danielmartin
danielmartin / Magit-change-commit-author.el
Last active September 21, 2020 21:15
Press "h" in a Magit interactive rebase to change the commit author of some commits. Username completion is provided by the git shortlog.
(defun dm/change-commit-author (arg)
"Change the commit author during an interactive rebase in Magit.
With a prefix argument, insert a new change commit author command
even when there is already another rebase command on the current
line. With empty input, remove the change commit author action
on the current line, if any."
(interactive "P")
(let ((author
(magit-transient-read-person "Select a new author for this commit"
nil
@danielmartin
danielmartin / XcodeNewBuildSystemSettings.json
Created February 23, 2020 14:37
Complete list of Xcode new build system settings and their documentation in JSON format.
This file has been truncated, but you can view the full file.
[
{
"spec": "com.apple.compilers.metal",
"path": "/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/Metal.xcplugin/Contents/Resources/Metal Compiler.xcspec",
"options": [
{
"name": "CLANG_DIAGNOSTICS_FILE"
},
{
"name": "MTLCOMPILER_DEPENDENCY_INFO_FILE"
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active March 9, 2024 02:00
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@danielmartin
danielmartin / xcode-switch-scheme-behavior.org
Created October 19, 2019 17:45
This gist describes how to switch Xcode schemes and run destinations using keybindings and Xcode behaviors.

How to Switch Xcode Schemes Quickly Using Keybindings

If you have a lot of schemes in your Xcode project, searching for the one you want to run may be slow, even if you use the “search as you type” feature. Because of this, you may choose to hide or not generate schemes that you don’t regularly use. Here’s an example of an Xcode project with a lot of schemes:

https://user-images.githubusercontent.com/1573717/67147042-93bec700-f280-11e9-869f-83bcb23eb252.png

import Foundation
import UIKit
/// Some helpers for having nice test assertions.
public func expectationFailure(
_ reason: String,
trace message: String) {
print(reason, terminator: reason == "" ? "" : "\n")
print(message, terminator: message == "" ? "" : "\n")
}
@danielmartin
danielmartin / copy-as-rtf.el
Created July 6, 2019 18:13
Export an Org region to RTF and copy it to the clipboard. Ideal for copying source code blocks to Google Docs and preserve syntax highlighting and indentation.
(defun dm/copy-as-rtf ()
"Export region to RTF and copy it to the clipboard."
(interactive)
(save-window-excursion
(let* ((buf (org-export-to-buffer 'html "*Formatted Copy*" nil nil t t))
(html (with-current-buffer buf (buffer-string))))
(with-current-buffer buf
(shell-command-on-region
(point-min)
(point-max)
@danielmartin
danielmartin / sourcekit-lsp.txt
Created November 23, 2018 09:32
sourcekit-lsp logs
lsp--stdio-wait: Content-Length: 1534
{
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"processId": 512,
"rootPath": "/Users/dmartin/Downloads/CryptoSwift-master/Sources/CryptoSwift/",
"rootUri": "file:///Users/dmartin/Downloads/CryptoSwift-master/Sources/CryptoSwift/",
"capabilities": {
@danielmartin
danielmartin / Ccls.crash
Created September 2, 2018 22:04
Ccls crash
Process: ccls [68808]
Path: /Users/USER/*/ccls
Identifier: ccls
Version: 0
Code Type: X86-64 (Native)
Parent Process: Emacs-x86_64-10_10 [64034]
Responsible: ccls [68808]
User ID: 502
Date/Time: 2018-09-03 00:03:17.227 +0200
@danielmartin
danielmartin / ccls.crash
Created September 2, 2018 21:37
UBSAN crash in ccls
Process: ccls [68329]
Path: /Users/USER/*/ccls
Identifier: ccls
Version: 0
Code Type: X86-64 (Native)
Parent Process: Emacs-x86_64-10_10 [64034]
Responsible: ccls [68329]
User ID: 502
Date/Time: 2018-09-02 23:19:06.962 +0200