Improve highlighting loop and language support

This commit is contained in:
Timothy Warren 2019-10-25 10:47:44 -04:00
parent 5566441dc3
commit 17283f5011
4 changed files with 41 additions and 8 deletions

2
.gitignore vendored
View File

@ -167,3 +167,5 @@ tags
[._]*.un~ [._]*.un~
# End of https://www.gitignore.io/api/vim,emacs,composer,jetbrains+all # End of https://www.gitignore.io/api/vim,emacs,composer,jetbrains+all
kilo.log

13
kilo
View File

@ -10,6 +10,19 @@ define('KILO_VERSION', '0.0.1');
define('KILO_TAB_STOP', 4); define('KILO_TAB_STOP', 4);
define('KILO_QUIT_TIMES', 3); define('KILO_QUIT_TIMES', 3);
// Log notices/errors/warnings to file
set_error_handler(static function (int $no, $str, $file, $line, $context) {
$msg = print_r([
'errno' => $no,
'message' => $str,
'file' => $file,
'line' => $line,
'context' => $context,
], TRUE);
file_put_contents('kilo.log', $msg, FILE_APPEND);
}, -1);
// Set up autoloading // Set up autoloading
require_once __DIR__ . '/src/functions.php'; require_once __DIR__ . '/src/functions.php';
require_once __DIR__ . '/src/hldb.php'; require_once __DIR__ . '/src/hldb.php';

View File

@ -112,16 +112,16 @@ class Editor {
foreach (get_hldb() as $syntax) foreach (get_hldb() as $syntax)
{ {
$i = 0; foreach ($syntax->filematch as $searchExt)
while ($syntax->filematch[$i])
{ {
$is_ext = ($syntax->filematch[$i][0] === '.'); $is_ext = (strpos($searchExt, '.') === 0);
if ( if (
($is_ext && ( ! strcmp($ext, $syntax->filematch[$i]))) || ($is_ext && ( ! strcmp($ext, $searchExt))) ||
(( ! $is_ext) && strpos($this->filename, $syntax->filematch{$i}) !== FALSE) (( ! $is_ext) && strpos($this->filename, $searchExt) !== FALSE)
) { ) {
$this->syntax = $syntax; $this->syntax = $syntax;
// Update the syntax highlighting for all the rows of the file
for ($i = 0; $i < $this->numRows; $i++) for ($i = 0; $i < $this->numRows; $i++)
{ {
$this->rows[$i]->update(); $this->rows[$i]->update();
@ -129,8 +129,6 @@ class Editor {
return; return;
} }
$i++;
} }
} }
} }

View File

@ -10,10 +10,30 @@ function get_hldb(): array
{ {
$db = [ $db = [
Syntax::new( Syntax::new(
'c', 'C',
['.c', '.h', '.cpp'], ['.c', '.h', '.cpp'],
Syntax::HIGHLIGHT_NUMBERS, Syntax::HIGHLIGHT_NUMBERS,
), ),
Syntax::new(
'CSS',
['.css', '.less', '.sass', 'scss'],
Syntax::HIGHLIGHT_NUMBERS,
),
Syntax::new(
'JavaScript',
['.js', '.jsx', '.ts', '.tsx', '.jsm', '.es'],
Syntax::HIGHLIGHT_NUMBERS,
),
Syntax::new(
'PHP',
['.php'],
Syntax::HIGHLIGHT_NUMBERS,
),
Syntax::new(
'Rust',
['.rs'],
Syntax::HIGHLIGHT_NUMBERS,
),
]; ];
} }