4 Commits

Author SHA1 Message Date
a03dd0c433 bump version
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
2025-11-24 22:52:25 -08:00
561faf537c Updating docs. 2025-11-24 22:51:10 -08:00
3a36b35c1f support running cloc over the file 2025-11-24 22:51:10 -08:00
Jeremy O'Brien
b1cb2532f6 add flake + default.nix 2025-11-24 22:43:40 -08:00
6 changed files with 135 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
project(ke C) # Specify C language explicitly
set(CMAKE_C_STANDARD 99)
set(KE_VERSION "1.3.1")
set(KE_VERSION "1.3.2")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")

27
default.nix Normal file
View File

@@ -0,0 +1,27 @@
{
lib,
installShellFiles,
stdenv,
...
}:
stdenv.mkDerivation {
pname = "ke";
version = "1.3.2";
src = lib.cleanSource ./.;
nativeBuildInputs = [ installShellFiles ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp ke $out/bin/
runHook postInstall
'';
postInstall = ''
installManPage ke.1
'';
}

27
flake.lock generated Normal file
View File

@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1763835633,
"narHash": "sha256-HzxeGVID5MChuCPESuC0dlQL1/scDKu+MmzoVBJxulM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "050e09e091117c3d7328c7b2b7b577492c43c134",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

18
flake.nix Normal file
View File

@@ -0,0 +1,18 @@
{
description = "Kyle's Text Editor";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs =
{ self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in
{
packages.x86_64-linux = {
default = pkgs.callPackage ./default.nix { };
};
};
}

33
ke.1
View File

@@ -19,21 +19,26 @@ is
K-command mode is entered using C-k. This is taken from Wordstar and just
so happens to be blessed with starting with a most excellent letter of
grandeur. Many commands work with and without control; for example,
saving a file can be done with either C-k s or C-k C-s.
.Pp
saving a file can be done with either C-k s or C-k C-s. Other commands work
with ESC or CTRL.
.Sh K-COMMANDS
.Bl -tag -width xxxxxxxxxxxx -offset indent
.It C-k BACKSPACE
Delete from the cursor to the beginning of the line.
.It C-k SPACE
Toggle the mark.
.It C-k d
Delete from the cursor to the end of the line.
.It C-k C-d
Delete the entire link.
Delete the entire line.
.It C-k e
Edit a new file. Also C-k C-e.
.It C-k f
Incremental find.
.It C-k g
Go to a specific line. Also C-k C-g.
.It C-k l
List the number of lines of code in a saved file.
.It C-k m
Run make(1).
.It C-k q
@@ -47,6 +52,28 @@ Yank the killring.
.It C-k \[char92]
Dump core.
.El
.Sh OTHER KEYBINDINGS
.Bl -tag -width xxxxxxxxxxxx -offset indent
.It C-l
Refresh the display.
.It C-s
Incremental find.
.It C-w
Kill the region if the mark is set.
.It C-y
Yank the killring.
.It ESC BACKSPACE
Delete the previous word.
.It ESC b
Move to the previous word.
.It ESC d
Delete the next word.
.It ESC f
Move to the next word.
.It ESC w
Save the region (if the mark is set) to the killring.
.It
.El
.Sh FIND
The find operation is an incremental search. The up or left arrow keys will
go to the previous result, while the down or right arrow keys will go to

42
main.c
View File

@@ -24,6 +24,7 @@
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#ifndef KE_VERSION
@@ -1714,30 +1715,52 @@ newline(void)
char *
get_cloc_code_lines(const char* filename)
{
// Build the shell command dynamically
char command[512];
char command[512];
char buffer[256];
char *result = NULL;
FILE *pipe = NULL;
size_t len = 0;
if (editor.filename == NULL) {
snprintf(command, sizeof(command),
"buffer has no associated file.");
result = malloc((strnlen(command, sizeof(command))) + 1);
assert(result != NULL);
strcpy(result, command);
return result;
}
if (editor.dirty) {
snprintf(command, sizeof(command),
"buffer must be saved first.");
result = malloc((strnlen(command, sizeof(command))) + 1);
assert(result != NULL);
strcpy(result, command);
return result;
}
snprintf(command,
sizeof(command),
"cloc --quiet %s | tail -2 | head -1 | awk '{print $5}'",
filename);
// Open a pipe to run the command
FILE *pipe = popen(command, "r");
pipe = popen(command, "r");
if (!pipe) {
return NULL; // Error opening pipe
snprintf(command, sizeof(command), "Error getting LOC: %s", strerror(errno));
result = (char *)malloc(sizeof(buffer) + 1);
return NULL;
}
// Read the output (single line/number)
char buffer[256];
if (fgets(buffer, sizeof(buffer), pipe) != NULL) {
// Remove trailing newline
size_t len = strlen(buffer);
len = strlen(buffer);
if (len > 0 && buffer[len - 1] == '\n') {
buffer[len - 1] = '\0';
}
// Allocate and copy the string
char *result = malloc(strlen(buffer) + 1);
result = malloc(strlen(buffer) + 1);
assert(result != NULL);
if (result) {
strcpy(result, buffer);
pclose(pipe);
@@ -1745,7 +1768,6 @@ get_cloc_code_lines(const char* filename)
}
}
// On error or empty output, return "0"
pclose(pipe);
char *zero = malloc(2);
if (zero) {