Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,6 @@ task:
only_if: $CIRRUS_BRANCH == "main" || $CIRRUS_PR != ""

matrix:
- name: Linux
container:
image: gcc:15.1
environment:
DEBIAN_FRONTEND: noninteractive
CFLAGS: -Werror -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=undefined -fuse-ld=gold
LC_ALL: C.UTF-8
UBSAN_OPTIONS: print_stacktrace=1
install_script: apt-get update -y && apt-get install --no-install-recommends -y cmake cscope libclang-dev llvm python3-pytest sqlite3 xxd vim
test_script: ./misc/ci.sh

- name: Linux, release build
container:
image: gcc:15.1
environment:
DEBIAN_FRONTEND: noninteractive
CFLAGS: -Werror -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=undefined -fuse-ld=gold
CMAKE_FLAGS: -DCMAKE_BUILD_TYPE=Release
LC_ALL: C.UTF-8
UBSAN_OPTIONS: print_stacktrace=1
install_script: apt-get update -y && apt-get install --no-install-recommends -y cmake cscope libclang-dev llvm python3-pytest sqlite3 xxd vim
test_script: ./misc/ci.sh

- name: macOS
macos_instance:
image: ghcr.io/cirruslabs/macos-runner:sequoia
environment:
CFLAGS: -Werror -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=undefined
PATH: /opt/homebrew/opt/llvm/bin:${PATH}
UBSAN_OPTIONS: print_stacktrace=1
install_script: brew update && brew install coreutils cscope llvm && env PIP_BREAK_SYSTEM_PACKAGES=1 python3 -m pip install pytest
test_script: ./misc/ci.sh

- name: C formatting
container:
image: silkeh/clang:19
Expand Down
58 changes: 57 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
set -u
set -x
uname -rms
pkg install -y bash cmake cscope git llvm python3 py311-pytest sqlite3 py311-sqlite3 vim
pkg install -y bash cmake cscope git llvm python3 devel/py-pytest sqlite3 databases/py-sqlite3 vim
python3 --version
git clone --no-checkout --recurse-submodules -- ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} wd
cd wd
Expand All @@ -37,3 +37,59 @@ jobs:
printf "find-me says: "
./build/test/find-me/find-me
cmake --install build

macos26:
name: macOS
runs-on: macos-26-intel
env:
CFLAGS: -Werror -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=address,undefined
UBSAN_OPTIONS: print_stacktrace=1
steps:
- run: python3 --version
- run: brew update
- run: brew install coreutils cscope llvm
- run: env PIP_BREAK_SYSTEM_PACKAGES=1 python3 -m pip install pytest
- run: echo "cloning ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
- run: git clone --no-checkout --recurse-submodules -- ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} wd
- run: >
cd wd &&
git fetch -- origin ${{ github.event.pull_request.head.sha }} &&
git checkout FETCH_HEAD &&
./misc/ci.sh

ubuntu2604:
name: Linux
runs-on: ubuntu-26.04
env:
DEBIAN_FRONTEND: noninteractive
CFLAGS: -Werror -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=address,undefined
UBSAN_OPTIONS: print_stacktrace=1
steps:
- run: sudo apt-get update
- run: sudo apt-get install --no-install-recommends -y cscope libclang-dev llvm python3-pytest xxd vim
- run: echo "cloning ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
- run: git clone --no-checkout --recurse-submodules -- ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} wd
- run: >
cd wd &&
git fetch -- origin ${{ github.event.pull_request.head.sha }} &&
git checkout FETCH_HEAD &&
./misc/ci.sh

ubuntu2604_release:
name: Linux, release build
runs-on: ubuntu-26.04
env:
DEBIAN_FRONTEND: noninteractive
CFLAGS: -Werror -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=address,undefined
CMAKE_FLAGS: -DCMAKE_BUILD_TYPE=Release
UBSAN_OPTIONS: print_stacktrace=1
steps:
- run: sudo apt-get update
- run: sudo apt-get install --no-install-recommends -y cscope libclang-dev llvm python3-pytest xxd vim
- run: echo "cloning ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
- run: git clone --no-checkout --recurse-submodules -- ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} wd
- run: >
cd wd &&
git fetch -- origin ${{ github.event.pull_request.head.sha }} &&
git checkout FETCH_HEAD &&
./misc/ci.sh
4 changes: 4 additions & 0 deletions clink/src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ static int handle_select(void) {
results.rows[select_index].lineno,
results.rows[select_index].colno, clink_repl,
clink_repl == NULL ? NULL : database);
} else if (clink_is_editor_emacs()) {
(void)clink_emacs_open(results.rows[select_index].path,
results.rows[select_index].lineno,
results.rows[select_index].colno);
} else {
(void)open_editor(results.rows[select_index].path);
}
Expand Down
3 changes: 2 additions & 1 deletion libclink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ add_library(libclink
src/eat_num.c
src/eat_rest_of_line.c
src/editor_open.c
src/emacs_open.c
src/get_environ.c
src/get_id.c
src/have_cscope.c
src/is_editor_vim.c
src/is_editor.c
src/iter.c
src/make_relative_to.c
src/mmap.c
Expand Down
2 changes: 1 addition & 1 deletion libclink/include/clink/clink.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include <clink/db.h>
#include <clink/debug.h>
#include <clink/def.h>
#include <clink/editor.h>
#include <clink/generic.h>
#include <clink/iter.h>
#include <clink/python.h>
#include <clink/symbol.h>
#include <clink/tablegen.h>
#include <clink/version.h>
#include <clink/vim.h>
16 changes: 16 additions & 0 deletions libclink/include/clink/vim.h → libclink/include/clink/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ CLINK_API int clink_vim_open(const char *filename, unsigned long lineno,
unsigned long colno, const char *cscopeprg,
const clink_db_t *db);

/** does the user’s editor look like Emacs?
*
* \return True if the editor appears Emacs-alike
*/
CLINK_API bool clink_is_editor_emacs(void);

/** open Emacs at the given position in the given file
*
* \param filename File to open with Emacs
* \param lineno Line number to position cursor at within the file
* \param colno Column number to position cursor at within the file
* \return Emacs’s exit status
*/
CLINK_API int clink_emacs_open(const char *filename, unsigned long lineno,
unsigned long colno);

/** open the given editor with the given file
*
* This is a simple wrapper around exec-ing `{editor, "--", filename}`. This is
Expand Down
2 changes: 1 addition & 1 deletion libclink/src/db_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int clink_db_open(clink_db_t **db, const char *path) {
slash[1] = '\0';
d->dir = abs;
} else {
char *slash = strrchr(path, '/');
const char *const slash = strrchr(path, '/');
d->dir = strndup(path, (size_t)(slash + 1 - path));
d->filename = strdup(slash + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion libclink/src/editor_open.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "run.h"
#include <clink/vim.h>
#include <clink/editor.h>
#include <errno.h>
#include <stddef.h>

Expand Down
50 changes: 50 additions & 0 deletions libclink/src/emacs_open.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "debug.h"
#include "run.h"
#include <clink/editor.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

int clink_emacs_open(const char *filename, unsigned long lineno,
unsigned long colno) {

// check filename is valid
if (ERROR(filename == NULL))
return EINVAL;

// check line number is valid
if (ERROR(lineno == 0))
return EINVAL;

// check column number is valid
if (ERROR(colno == 0))
return EINVAL;

int rc = 0;
char *jump = NULL;

// construct a directive telling Emacs to jump to the given position
if (ERROR(asprintf(&jump, "+%lu:%lu", lineno, colno) < 0)) {
rc = ENOMEM;
goto done;
}

// assume the user’s preferred editor is Emacs, but still locate the path to
// it
const char *emacs = getenv("VISUAL");
if (emacs == NULL)
emacs = getenv("EDITOR");
if (emacs == NULL)
emacs = "emacs";

// construct a argument vector to invoke Emacs
char const *argv[] = {emacs, jump, "--", filename, NULL};

// run it
rc = run(argv);

done:
free(jump);

return rc;
}
37 changes: 35 additions & 2 deletions libclink/src/is_editor_vim.c → libclink/src/is_editor.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "debug.h"
#include <assert.h>
#include <clink/vim.h>
#include <clink/editor.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -9,7 +9,7 @@
*
* \param base Start of the path to test
* \param length Number of bytes in the path
* \param alias An alias for Vim
* \param alias An alias for Emacs or Vim
* \return True if this is a path to a binary of the given alias
*/
static bool is(const char *base, size_t length, const char *alias) {
Expand Down Expand Up @@ -67,3 +67,36 @@ bool clink_is_editor_vim(void) {

return false;
}

bool clink_is_editor_emacs(void) {

// priority 1: `$VISUAL`
const char *editor = getenv("VISUAL");

// priority 2: `$EDITOR`
if (editor == NULL)
editor = getenv("EDITOR");

// else fallback to Vim
if (editor == NULL)
editor = "vim";

// `$EDITOR` can contain something like “emacs -q”, so assume only the first
// word is the actual path
const char *space = strchr(editor, ' ');
const size_t len = space == NULL ? strlen(editor) : (size_t)(space - editor);

// aliases Emacs goes by
const char *EMACS_NAMES[] = {"emacs"};

for (size_t i = 0; i < sizeof(EMACS_NAMES) / sizeof(EMACS_NAMES[0]); ++i) {
if (is(editor, len, EMACS_NAMES[i])) {
DEBUG("editor \"%s\" matched \"%s\"", editor, EMACS_NAMES[i]);
return true;
} else {
DEBUG("editor \"%s\" did not match \"%s\"", editor, EMACS_NAMES[i]);
}
}

return false;
}
2 changes: 1 addition & 1 deletion libclink/src/vim_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "debug.h"
#include "run.h"
#include <assert.h>
#include <clink/vim.h>
#include <clink/editor.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion libclink/src/vim_read.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "debug.h"
#include <clink/vim.h>
#include <clink/editor.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion libclink/src/vim_read_into.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "sql.h"
#include <assert.h>
#include <clink/db.h>
#include <clink/vim.h>
#include <clink/editor.h>
#include <errno.h>
#include <sqlite3.h>
#include <stddef.h>
Expand Down
8 changes: 1 addition & 7 deletions misc/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,4 @@ cmake --build build --target check
printf "find-me says: "
./build/test/find-me/find-me

if [ "$(uname -s)" = "Darwin" ]; then
SUDO=sudo
else
# sudo not needed
SUDO=
fi
${SUDO} cmake --install build
sudo cmake --install build
Loading